Michael Geary schrieb: >> From: Dossy Shiobara >> >> I'm surprised there's no .reverse(). i.e.: >> >> $(collection).reverse().each(...) >> > > Great idea! > > How about the world's smallest plugin: > > jQuery.fn.reverse = [].reverse; > That's some really great stuff! It took me some time to figure out that you are simply extending jQuery with an existing built-in function... Very neat. > Armed with this knowledge, one might be tempted to load all the Array > methods in one fell swoop: > > jQuery.fn.prototype = Array.prototype; > > But that does not work, presumably because jQuery is already being a bit > sneaky about its Array-like behavior. > You try to assign the Array prototype to the prototype of the jQuery prototype, right?
After some experiments on the firebug console, I think the reason for this no working is the Array prototype: It is just an empty error, see for yourself: console.debug( Array.prototype ); Therefore jQuery.fn.extend(Array.prototype) doesn't work either. But we could just add something like this: var arr = "reverse,pop,push,join,shift,rest of the array methods".split(","); for(var i=0; i<arr.length; i++) { jQuery.fn[arr[i]] = [][arr[i]]; } -- Jörn _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/