아래 코드를 살펴 보시기 바랍니다. 나는 calllback.call이하는 일을 정확히 수행 할 수 없습니다.jquery에서 callback.call 함수 이해
또한 this와 this [i]의 차이점과 if (callback.call (this, this [i]))가 true 또는 false로 평가되는 방법을 알 수 없습니다.
Array.prototype.each = function(callback) {
var i = 0;
while (i < this.length) {
callback.call(this, this[i]);
i++;
}
return this;
};
Array.prototype.map = function(callback) {
var i = this.length;
var found = []
while (i--) {
if(callback.call(this, this[i])) {
found.push(this[i]);
}
}
return found;
};
기능은 아래라고 :
Array.each(function(value){
...
})
Array.map(function(value){
...
})
두 경우 모두'each '와'map'에는 함수가 할당됩니다. – CodingYoshi
'[1,2,3] .each (function() {/ * do something * /})'같은 함수를 호출하지 않겠습니까? –