So there is a reason? ;)

In this example, I wouldn't want Array to implement "increment" as a
method -- only Numbers should have increment available (just as Array
doesn't have "addClass" but Elements does). The example may be
trivial, but if it was a list of more complex instances it becomes
more evident.

On Fri, Dec 6, 2013 at 2:22 PM, Aaron Newton <anut...@gmail.com> wrote:
> Why not just extend Array?
>
>
> On Fri, Dec 6, 2013 at 11:21 AM, Regis <regis.gaug...@gmail.com> 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 mootools-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "MooTools Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mootools-users/KBiU3Rq8SE8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> mootools-users+unsubscr...@googlegroups.com.
> 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 mootools-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to