minor
This commit is contained in:
parent
662f5193aa
commit
a7e2c43564
1 changed files with 2 additions and 2 deletions
|
@ -15,7 +15,7 @@ alert( user2.name ); // Pete (worked!)
|
|||
|
||||
It worked, because `User.prototype.constructor == User`.
|
||||
|
||||
..But if someone, so to speak, overwrites `User.prototype` and forgets to recreate `"constructor"`, then it would fail.
|
||||
..But if someone, so to speak, overwrites `User.prototype` and forgets to recreate `constructor` to reference `User`, then it would fail.
|
||||
|
||||
For instance:
|
||||
|
||||
|
@ -41,4 +41,4 @@ Here's how `new user.constructor('Pete')` works:
|
|||
2. Then it follows the prototype chain. The prototype of `user` is `User.prototype`, and it also has nothing.
|
||||
3. The value of `User.prototype` is a plain object `{}`, its prototype is `Object.prototype`. And there is `Object.prototype.constructor == Object`. So it is used.
|
||||
|
||||
At the end, we have `let user2 = new Object('Pete')`. The built-in `Object` constructor ignores arguments, it always creates an empty object -- that's what we have in `user2` after all.
|
||||
At the end, we have `let user2 = new Object('Pete')`. The built-in `Object` constructor ignores arguments, it always creates an empty object, similar to `let user2 = {}`, that's what we have in `user2` after all.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue