我正在尝试使用数组..what的扩展,我应该在constructor..Here中放入代码
class List extends Array
constructor: ()->
super arguments
this
list = new List("hello","world")
alert list[0]似乎不起作用..
发布于 2012-03-14 01:52:51
没有简单的方法可以从数组原型中“继承”。您应该使用组合,即
class List
constructor: ()->
this.array = new Array(arguments);
getArray :()->
this.array
list = new List("hello","world")
alert list.getArray()[0]否则,您将花费时间来实现复杂的解决方案,一旦您尝试解析数组或访问其长度值,这些解决方案就会失败。
关于这个问题的更多信息:
http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
发布于 2012-03-14 00:30:50
我最近没有使用咖啡脚本,所以这只是一个猜测,但可能是这样的:
class List extends [].prototype可能行得通?
编辑:根据"mu is too short“的评论,这个问题看起来根本与咖啡脚本无关。你可能会发现这个相关的帖子很有用,因为选择的答案提供了两种可能的解决方案:Is this a reasonable way to 'subclass' a javascript array?
https://stackoverflow.com/questions/9688009
复制相似问题