This code iterates over just the enumerable properties of an object:
for (variable in object)
statement
The following code iterates over all properties not just the enumerable ones:
function getAllPropertyNames(obj) {
var result = [];
while (obj) {
Array.prototype.push.apply(result, Object.getOwnPropertyNames(obj));
obj = Object.getPrototypeOf(obj);
}
return result;
}
When does the loop
while (obj)
break?How do lines within the
while
block work to add the own property names ofobj
toresult
?