Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the-prototype-pattern.md #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Person.prototype = {
}
```

前面介绍过,没创建一个函数,就会同时创建它的原型对象,这个对象自动获得构造函数。而这里的语法,这里相当于重写了实例的原型对象,相应地原型对象中的构造函数 `constructor` 亦被覆盖,不再指向 `Person` 函数。此时,尽管 `instanceof` 操作符还能返回正确的结果,但通过 `constructor` 已经无法确定对象的类型了。
前面介绍过,每创建一个函数,就会同时创建它的原型对象,这个对象自动获得构造函数。而这里的语法,这里相当于重写了实例的原型对象,相应地原型对象中的构造函数 `constructor` 亦被覆盖,不再指向 `Person` 函数。此时,尽管 `instanceof` 操作符还能返回正确的结果,但通过 `constructor` 已经无法确定对象的类型了。

当然,我们可以手动为它设置回适当的值。但是,以这种方式重设 `constructor` 属性回导致它的 `[[Enumerable]]` 特性被设置为 `true`。默认情况下,原生的 `constructor` 属性是不可枚举的。

Expand Down