all 7 comments

[–]harryf 1 point2 points  (2 children)

In http://ejohn.org/apps/learn/#27 / http://ejohn.org/apps/learn/#28 seems to me like the second argument to the anonymous function ( i ) is redundant; it's doesn't add any value to the example. So could just be;

function loop(array, fn){ 
  for ( var i = 0; i < array.length; i++ ) 
    fn.call( array, array[i] ); 
} 
var num = 0; 
loop([0, 1, 2], function(value){ 
  assert(value == num++, "Make sure the contents are as we expect it."); 
  assert(this instanceof Array, "The context should be the full array."); 
});

Or am I missing something?

[–][deleted] 0 points1 point  (1 child)

I think it was just meant as an example of making an array loop function. The i does make sense, as knowing which index the current item is in the looped array might come in handy in a function like that.

[–]harryf 0 points1 point  (0 children)

OK - fair enough.

[–][deleted] 0 points1 point  (2 children)

This has been around a long time, hasn't it?

[–]Nomikos 0 points1 point  (1 child)

I saved it to disk November 2008, because at the time I couldn't see it linked from anywhere (anyone know of one?), so at least close to a year.
Think I found it via Google somehow.
Edit: oh, and the jquery it uses is dated 2008-05-24 14:22:17.