/ Published in: JavaScript
hope you enjoy - thanks to Tom Duff (for implementation in C), Dean Edwards, and Nicholas Zakas for the idea
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
forEach = (function() { /** * USAGE * instead of: * for(var i=0, il=some.length; i<il; i++) * Use this: * forEach(object, function(i){ * i.doSomething(); * }, context); * * or this: * forEach(object, function(i){ * i.doSomething(); * }); * * @param object elementNodeList || array * @param block function * @param context inherited by the this object */ return function(object, block, context) { var len = Math.floor(object.length / 4), left = object.length % 4, i = 0; if(left > 0){ do { block.call(context, object[i++], i, object); } while (--left > 0); }; while(len-- > 0) { block.call(context, object[i++], i, object); block.call(context, object[i++], i, object); block.call(context, object[i++], i, object); block.call(context, object[i++], i, object); }; }; })();
URL: http://www.six-degrees.com/six-degrees.html