We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
所有带 new 的函数调用。
function Foo() { // ... } var a = new Foo();
Foo 和你程序中的其他函数没有任何区别。Foo 函数本身不是构造函数,但是当且仅当使用 new 时,函数调用会变成 “构造函数调用”。
JavaScript 中的对象拥有的一个特殊的 [[prototype]] 内置属性。这个属性其实就是对其他对象的引用。
function Foo() { // ... } var a = new Foo(); Object.getPrototypeOf(a) === Foo.prototype; // true
调用 new Foo() 时会创建 a 这个对象,创建过程的其中一步是给 a 一个内部的 [[prototype]] 链接,关联到 Foo.prototype 指向的那个对象。
[[prototype]] 的作用是:如果在对象上没有找到需要的属性或者方法引用,引擎就会继续在 [[prototype]] 关联的对象上进行查找。同理,如果在后者中也没有找到需要的引用就会继续查找它的 [[prototype]],以此类推。这一系列对象的链接被称为“原型链”。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
构造函数
所有带 new 的函数调用。
Foo 和你程序中的其他函数没有任何区别。Foo 函数本身不是构造函数,但是当且仅当使用 new 时,函数调用会变成 “构造函数调用”。
[[prototype]]
JavaScript 中的对象拥有的一个特殊的 [[prototype]] 内置属性。这个属性其实就是对其他对象的引用。
调用 new Foo() 时会创建 a 这个对象,创建过程的其中一步是给 a 一个内部的 [[prototype]] 链接,关联到 Foo.prototype 指向的那个对象。
原型链
[[prototype]] 的作用是:如果在对象上没有找到需要的属性或者方法引用,引擎就会继续在 [[prototype]] 关联的对象上进行查找。同理,如果在后者中也没有找到需要的引用就会继续查找它的 [[prototype]],以此类推。这一系列对象的链接被称为“原型链”。
一张老图
The text was updated successfully, but these errors were encountered: