Update article.md
Wording and punctuation of 'hasOwnProperty' 'for..in' loop question and answer.
This commit is contained in:
parent
f97b2fd1e2
commit
940a9b710d
1 changed files with 2 additions and 2 deletions
|
@ -308,9 +308,9 @@ Here we have the following inheritance chain: `rabbit` inherits from `animal`, t
|
|||
|
||||
Note, there's one funny thing. Where is the method `rabbit.hasOwnProperty` coming from? We did not define it. Looking at the chain we can see that the method is provided by `Object.prototype.hasOwnProperty`. In other words, it's inherited.
|
||||
|
||||
...But why `hasOwnProperty` does not appear in `for..in` loop, like `eats` and `jumps`, if it lists all inherited properties.
|
||||
...But why does `hasOwnProperty` not appear in the `for..in` loop like `eats` and `jumps` do, if `for..in` lists inherited properties?
|
||||
|
||||
The answer is simple: it's not enumerable. Just like all other properties of `Object.prototype`, it has `enumerable:false` flag. That's why they are not listed.
|
||||
The answer is simple: it's not enumerable. Just like all other properties of `Object.prototype`, it has `enumerable:false` flag. And `for..in` only lists enumerable properties. That's why it and the rest of the `Object.prototype` properties are not listed.
|
||||
|
||||
```smart header="Almost all other key/value-getting methods ignore inherited properties"
|
||||
Almost all other key/value-getting methods, such as `Object.keys`, `Object.values` and so on ignore inherited properties.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue