Why does a method using the shorthand method syntax not contain a prototype object

孤街醉人 提交于 2019-12-06 13:15:13

Why does obj1.bar contain the .prototype Object and obj2.bar does not?

Because it's a method definition. Methods are no constructors, they don't need one. (It's the same for class methods and for arrow functions, btw.)
In obj2 you used a function expression, which creates a function that can be used as a constructor (as has been always the case in ES5).

Are all three objects prototype objects?

An object is not a "prototype object". Every object can be used as the prototype of some other object or not.

Why does the fact of obj2.bar not having a .prototype not influence the way in which it binds this?

Why would it? It's still a method that is supposed to have a dynamic this value, otherwise it could not be shared.

Only the arrow functions that you used in obj3 have special behaviour in this regard. See Methods in ES6 objects: using arrow functions for details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!