javascript - __proto__ VS。 JavaScript 中的原型(prototype)

标签 javascript prototype javascript-objects prototypal-inheritance

This figure again shows that every object has a prototype. Constructor function Foo also has its own __proto__ which is Function.prototype, and which in turn also references via its __proto__ property again to the Object.prototype. Thus, repeat, Foo.prototype is just an explicit property of Foo which refers to the prototype of b and c objects.

var b = new Foo(20);
var c = new Foo(30);

__proto__prototype有什么区别?

enter image description here

图取自dmitrysoshnikov.com .

注意:现在有 a 2nd edition (2017)到上面2010年的文章。

最佳答案

__proto__是在查找链中用于解析方法等的实际对象。prototype是用于构建 __proto__ 的对象当您使用 new 创建对象时:

( new Foo ).__proto__ === Foo.prototype
( new Foo ).prototype === undefined

关于javascript - __proto__ VS。 JavaScript 中的原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959727/

相关文章:

{} 和 [] 之间的 Javascript 区别

javascript - 如果对象值在数组中是唯一的,则执行此操作

javascript - 使用 Angular 5 在 firebase 中存储数据时无法读取未定义的属性 'push'

c - 声明一个以 FILE 作为参数的函数原型(prototype)

javascript - 在 JavaScript 中将对象引用作为函数参数传递

对象中对象的 Javascript 原型(prototype)继承

javascript - JS如何返回一个城市的居住人数?

javascript - 将键值分配给 JavaScript 对象中的另一个键值

javascript - Nodemailer - 动态传输器

JavaScript Isotope - 如何智能地创建多组过滤器以在一个容器上协同工作?