I'm trying to understand this a bit more clearly. When I extend modify the each function inside the Array prototype, How does calling func(this[i]) call the function passed into Array.each.
Since the function definition is function(func) and func is the parameter.
Does func = function(i) { alert(i) } and thus func(this[i]) = { function(this[i]) { alert(this[i]) } ?
Array.prototype.each = function(func) {
for (var i=0; i<this.length; i++) {
func(this[i]);
}
};
[1,2,3].each(function(i) {
alert(i);
});