Manu Masson
Manu Masson

Reputation: 1747

Why does this object property return NaN?

I have a undefined object at the top of my page:

var paddelY = {};

Then IN the draw loop, I define it (Otherwise I get an error that mouseY is undefined):

paddelY = { 
    1 : mouseY + height*0.03,  //Nuber
    2 : this[1] - height*0.00275 //NaN
};

However, if I were to log paddelY[2] to the console, it would be NaN.

Upvotes: 0

Views: 1364

Answers (1)

Marc B
Marc B

Reputation: 360802

You're defining a new object. this[1] won't be available until the entire object has been parsed, so you're doing undefined - height, which results in NaN.

paddelY = { 1 : mouseY + height *0.03 };
paddelY[2] = paddelY[1] - height*0.00275;

would work

Upvotes: 4

Related Questions