I am trying to use the extends for array ..what should I put in the constructor..Here is the code
class List extends Array
constructor: ()->
super arguments
this
list = new List("hello","world")
alert list[0]
Doesn't seem to work..
There is no easy way to "inherit" from the array prototype. You should use composition , i.e.
class List
constructor: ()->
this.array = new Array(arguments);
getArray :()->
this.array
list = new List("hello","world")
alert list.getArray()[0]
or you will spend your time implemented complicated solutions that will fail as soon as you try to parse the array or access its length value.
more on the issue :
http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With