> Hi, Maybe you could think of adding things like $A, $H,
> $S, $L where you could do something like:
>
> $L(['aaa', 'bbb']).each(fn)... would be nice
For those situations, why not extend the Array prototype? It makes for
cleaner syntax.
['aaa', 'bbb'].each(fn)
Array.prototype.each = function(f) {
for ( var i=0; i < this.length; i++ )
f(this[i], i);
};
Where prototype.js goes bad is by extending Javascript's foundation Object
object, which means all its new methods are visible when you use "for ( i in
obj )" syntax. Extending Array works fine as long as you always use
indexing.
Javascript 1.6 (Firefox) already has several useful array functions so you
can just conditionally add the same ones (or renamed versions) for other
browsers:
every() - runs a function on every item in the array and returns true if the
function returns true for every item.
filter() - runs a function on every item in the array and returns an array
of all items for which the function returns true.
forEach() - runs a function on every item in the array.
map() - runs a function on every item in the array and returns the results
in an array.
some() - runs a function on every item in the array and returns true if the
function returns true for any item.
http://developer.mozilla.org/en/docs/New_in_JavaScript_1.6
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/