gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:30:12 25 4
gpt4 key购买 nike

This figure again shows that every object has a prototype. Constructorfunction Foo also has its own __proto__ which is Function.prototype,and which in turn also references via its __proto__ property again tothe Object.prototype. Thus, repeat, Foo.prototype is just an explicitproperty 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/58239881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com