Javascript Arrays created with Object.create - not real Arrays?

天涯浪子 提交于 2019-11-27 22:26:53
Tim Down

The short answer is no. This article explains it all in some detail.

No, you cannot. Object.create is all about prototypes, but both [] and Object.create(Array.prototype) inherit from the same prototype object.

What you call "desired Object.prototype.toString behaviour" is the internal [[Class]] of the object, which is impossible to set up with Object.create. Creating "true arrays" (with an Array class and special array behaviour - indexed properties, .length) is only possible by using array literals or calling the Array constructor.

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