简体   繁体   English

少量对象是否具有原型属性?

[英]Does small number of objects have a prototype property?

I'm going through the book JavaScript: The Definitive Guide 7th edition.我正在阅读本书 JavaScript:权威指南第 7 版。

And in objects section I encountered a strange phrase that在对象部分我遇到了一个奇怪的短语

Remember: almost all objects have a prototype, but only a relatively small number of objects have a prototype property.请记住:几乎所有对象都有原型,但只有相对少数的对象具有原型属性。 It is these objects with prototype properties that define the prototypes for all the other objects.正是这些具有原型属性的对象定义了所有其他对象的原型。

What I find confusing is that it says first, almost every object has a prototype and then says only a relatively small number of objects have a prototype property .我感到困惑的是,它首先说,几乎每个 object 都有一个原型,然后说只有相对少量的对象具有原型属性 I find these as two contradicting statements;我发现这是两个相互矛盾的陈述; how come almost every object has a prototype while everyone of them doesn't get to have prototype property.为什么几乎每个 object 都有原型,而每个人都没有原型属性。

Can you explain what above statement means?你能解释一下上面的说法是什么意思吗?

May be this can enlight you: (the sentence is not well formulated, almost all objects have a prototype chain inheritance, but only a relatively small number of objects defines a prototype property )可能是这样可以启发你:(这句话表述得不好, almost all objects have a prototype chain inheritance, but only a relatively small number of objects defines a prototype property

 function Foo() { } Foo.prototype.bar = function () {// prototype property on Foo console.log('bar'); }; const foo = new Foo(); console.log(foo.__proto__);// object const baz = Object.create(null); console.log(baz.__proto__);// undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM