Neat.. didn't know about the array-like object ability. Looking at the
moo source, I see you can also use it for Array.from(arguments), which
is very useful! So it seems you can use it on anything that is
isEnumerable, which basically means not a function and has a numeric
length property.
var arr = Array.from({length: 5});
(new Element('div', {'html':
JSON.encode(arr)})).inject(document.body); // yields
[null,null,null,null,null]
Nice to know..
In a previous project, I would use Array.from (actually the not-as-
fancy $splat back then) for more flexibility in accepting parameters
('parametric polymorphism').. like with a function like:
var addToList = function(obj) {
Array.from(obj).each(function(obj) {
$('msg').innerHTML += "<br/>Adding " + obj.name + " to list";
});
};
On Mar 23, 8:00 am, Fli7e <[email protected]> wrote:
> correct but why does typeof say "typeof map: function" .. i can't seem
> to find a functin in your code but an object ...
>
> On 23 Mrz., 14:43, Ryan Florence <[email protected]> wrote:
>
> > It also creates arrays out of array-like objects (like arguments, what
> > Slick returns, etc.)
>
> >http://jsfiddle.net/rpflorence/AU8WZ/
>
> > On Mar 23, 2011, at 6:24 AM, Steve Onnis wrote:
>
> > > Yes i read that. So basically all it does is [var] and creates an array
> > > of a
> > > single element with that element being the value of the argument
>
> > > -----Original Message-----
> > > From: Fli7e [mailto:[email protected]]
> > > Sent: Wednesday, 23 March 2011 10:52 PM
> > > To: MooTools Users
> > > Subject: [Moo] Re: erase from array not working
>
> > > It returns an Array if the Input is an Array ...
>
> > > from the Docs:
>
> > > Returns:
> > > (array) If the variable passed in is an array, returns the array.
> > > Otherwise, returns an array with the only element being the variable
> > > passed in.
>
> > > On 23 Mrz., 12:41, "Steve Onnis" <[email protected]> wrote:
> > >> Yeah figured that. I thought Array.from() would convert the string into
> > >> an
> > > array...i was wrong J
>
> > >> From: Andrea Dessì [mailto:[email protected]]
> > >> Sent: Wednesday, 23 March 2011 7:41 PM
> > >> To: [email protected]
> > >> Subject: Re: [Moo] erase from array not working
>
> > >> Hi Steve,
>
> > >> you are missing to split the value of the text input :)
>
> > >> have a look:http://jsfiddle.net/r8LSc/1/
>
> > >> --
> > >> Andrea
>
> > >> On Wed, Mar 23, 2011 at 05:42, Steve Onnis <[email protected]>
> > >> wrote:
>
> > >> Could someone have a quick look at this and maybe tell my why erase
> > > doesn’t work? Include is working but not erase
>
> > >>http://jsfiddle.net/r8LSc/
>
> > >> Thanks
>
> > >> Steve