I just found the example as follow code, the fork() function may be implement same as the Array.forEach(). So, my question is: why thisp must be passed the fun.call() and why the last argument is this.
Hope to receive your kindly support,
if (!Array.prototype.fork) {
Array.prototype.fork = function(fun /*, thisp*/ ) {
var len = this.length;
//console.log(this);
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
console.log(thisp);
for (var i = 0; i < len; i++) {
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}
var keywords = ["sdfsdf", "dfhgfh", "Học lập trình", "thehalfheart"]
keywords.fork(function(eachName, index) {
console.log(index + 1 + ". " + eachName);
}, 'rich');
this, but the code is not using it...fork? Where did you find this example code?elementandindexin the functionArray.forEach(function(element, index){}). I think thefork()function above is same asforEach(), so, i can understand now.forEach.