not proved features of class properties
"The property name is not placed into User.prototype. Instead, it is created by new before calling the constructor, it’s a property of the object itself." you are talking about some features of "class properties" but the example code doesn't show these features. I changed the example code to show that defining property out of the constructor method is different from defining method in class structure.
This commit is contained in:
parent
dcb9d87ab8
commit
4df1cb9bbd
1 changed files with 3 additions and 0 deletions
|
@ -318,6 +318,9 @@ class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
new User().sayHi();
|
new User().sayHi();
|
||||||
|
|
||||||
|
alert(User.prototype.sayHi); // placed in User.prototype
|
||||||
|
alert(User.prototype.name); // undefined, not placed in User.prototype
|
||||||
```
|
```
|
||||||
|
|
||||||
The property `name` is not placed into `User.prototype`. Instead, it is created by `new` before calling the constructor, it's a property of the object itself.
|
The property `name` is not placed into `User.prototype`. Instead, it is created by `new` before calling the constructor, it's a property of the object itself.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue