Subclassing Javascript Arrays. TypeError: Array.prototype.toString is not generic

后端 未结 7 1277
独厮守ぢ
独厮守ぢ 2020-11-28 06:30

Is it possible to subclass and inherit from javascript Arrays?

I\'d like to have my own custom Array object that has all the features of an Array, but contains addit

7条回答
  •  悲&欢浪女
    2020-11-28 07:16

    Juriy Zaytsev (@kangax) just today released a really good article on the subject.

    He explores various alternatives like the Dean Edwards iframe borrowing technique, direct object extension, prototype extension and the usage of ECMAScript 5 accessor properties.

    At the end there is no perfect implementation, each one has its own benefits and drawbacks.

    Definitely a really good read:

    • How ECMAScript 5 still does not allow to subclass an array

提交回复
热议问题