javascript - Minifying for{} loops -
i've got javascript for {} loops use repeatedly throughout project, similar this:
for (var = 0; < things.length; i++) { console.log(things[i]); // may different in different areas of project } i minified code, loops take lot of minified code. there way shorten above code this:
loop { console.log(things[i]); // may different in different areas of project } probably not above, idea. appreciated :)
a jquery-ish way that:
function each(arr, func) { ( var = 0; < arr.length; ++i ) { func(arr[i]); } } can called like:
each( things, function(thing) { console.log(thing); } ); or
each( things, function(thing) { console.log(thing); alert(thing); } ); etc.
Comments
Post a Comment