I've started learning pure JS by John Resig's book and found quite unclear example with call() function:
function forEach (list, callback) {
for (var i = 0; i < list.length; i++) {
callback.call(list[i],i)
};
}
var strings = [ 'hello', 'world', '!'];
forEach(strings, function(index){
console.log(strings[index]);
});
How it works? Can anybody explain?
thispointer for your method and the second (and subsequent) are the ones that gets passed to your function as arguments.