javascript object access performance
Posted
by youdontmeanmuch
on Stack Overflow
See other posts from Stack Overflow
or by youdontmeanmuch
Published on 2010-05-29T22:31:27Z
Indexed on
2010/05/29
22:32 UTC
Read the original article
Hit count: 233
In Javascript, when your getting a property of an object, is there a performance penalty to getting the whole object vs only getting a property of that object?
Also Keep in mind I'm not talking about DOM access these are pure simple Javascript objects.
For example:
Is there some kind of performance difference between the following code:
Assumed to be faster but not sure:
var length = some.object[key].length;
if(length === condition){
// Do something that doesnt need anything inside of some.object[key]
}
else{
var object = some.object[key];
// Do something that requires stuff inside of some.object[key]
}
I think this would be slower but not sure if it matters.
var object = some.object[key];
if(object.length === condition){
// Do something that doesnt need anything inside of some.object[key]
}
else{
// Do something that requires stuff inside of some.object[key]
}
© Stack Overflow or respective owner