hasOwnPropery is meant as a way to ensure that you are only iterating over values that belong to the object you are checking the property against. Meaning that you won't use cpu to process information on properties that live on the parent of the object you inherited from.
Also, I'm not sure what you mean by "hijacked"? I'm not sure how that plays into your argument about the object growing or not to use hasOwnPropery?
Sorry man, I'm still not understanding the message you are trying to convey. Is it that when looping through object literals that don't inherit from other objects, it's not necessary to include the hasOwnProperty check?
var prop;
var A = {
foo: 'bar',
fooFn: function () {}
};
var B = Object.create(a);
/**
* ensures that you are only looping through
* properties that belong only to B. Will not
* execute code on properties from A.
*/
for (prop in B) {
if (b.hasOwnProperty(prop)) {
console.log(b[prop]);
}
}
/**
* will execute code on not only properties on B
* but it will also loop through properties on A.
*/
for (prop in B) {
console.log(b[prop]);
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
hasOwnPropery
is meant as a way to ensure that you are only iterating over values that belong to the object you are checking the property against. Meaning that you won't use cpu to process information on properties that live on the parent of the object you inherited from.Also, I'm not sure what you mean by "hijacked"? I'm not sure how that plays into your argument about the object growing or not to use
hasOwnPropery
?Sorry man, I'm still not understanding the message you are trying to convey. Is it that when looping through object literals that don't inherit from other objects, it's not necessary to include the
hasOwnProperty
check?