Why not just extend Array?

On Fri, Dec 6, 2013 at 11:21 AM, Regis <[email protected]> wrote:

> I want to create a class, similar to Elements (just, not with elements)
> which behaves like an array, but with additional methods on it that can
> manipulate the objects within (which are all of the same type). I'm aware
> that the magical "length" behavior wouldn't work as expected.
>
> For example, is there any reason why something like this would not work as
> expected (as it seems to just fine):
>
> var Numbers = new Class({ Extends: Array, increment: function(){ var self
> = this; self.forEach(function(n, i){ self[i]++; }); return self; } });
> var n = new Numbers(); n.include(2).combine([3,4,5]).unshift(1); //
> [1,2,3,4,5]
> n.increment(); // [2,3,4,5,6]
>
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "MooTools Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"MooTools Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to