Clément
Clément

Reputation: 33

Why do i get a maximum call stack exceeded?

I don't know why i get a mximum call stack exceeded, i don't know from where it comes.

Thanks for helping!!

Function attributeMissions :

function attributeMissions(missions) {

var start;
var date = new Date();
var length;
var position = 2.1;
var start;

if (date.getMinutes() > 480 && date.getMinutes() < 1320) {
    var start = date.getMinutes();
}

if (locationMassage = !undefined) {
    length = date.getMinutes() - start;
}

var x, y;

Coordinates of location :

var locationMassage = {
    1: {
        x: 2.101,
        y: -0.3
    },
    2: {
        x: 2.102,
        y: -0.3
    },
    3: {
        x: 2.103,
        y: -0.3
    },
    4: {
        x: 2.104,
        y: -0.3
    },
    5: {
        x: 2.105,
        y: -0.3
    },
    6: {
        x: 2.106,
        y: -0.3
    },
    7: {
        x: 2.107,
        y: -0.3
    },
    8: {
        x: 2.108,
        y: -0.3
    },
    9: {
        x: 2.106,
        y: -0.3
    },
    10: {
        x: 2.26,
        y: -0.3
    }


};

Function setInterval to execute the function 5 minutes later :

setInterval(attributeMissions(start, length, 300000));

I want to return the location of locationMassage :

I think what i wrote is not correct

return {
    locationMassage: 1
};

}

Upvotes: 0

Views: 48

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 85012

setInterval(attributeMissions(start, length, 300000));

This code immediately calls attributeMissions, passing it in start, length, and 300000. Whatever is returned by attributeMissions gets passed into setInterval. So if this line of code was in attributeMissions (not clear from the examples you provided), then attributeMissions will call attributeMissions, which will call attributeMissions, and so on, leading to the stack overflow.

Instead of calling attributeMissions right away you want to pass a function into setInterval, such as like this:

setInterval(() => attributeMissions(start, length), 300000);

Upvotes: 2

Related Questions