Асинхронный map массива в Javascript (JavaScript)
Ревизии: current
Асинхронный map массива в Javascript с возвращением результата в callback функцию.
Автор: scarych
E-mail: mail[at]scarych[dot]ru
Array.prototype.amap = function (f,c) {
var t = this, r=[], l=t.length, e=0, i=0, b=function() {e++; if (e==l && c) c(r);}
while (i<l) { setTimeout( function(i) {return function () {r[i] = f(t[i]);b()};}(i), 0);; i++; }
}
var a = [1,2,3,4,5,6,7,8,9,10];
a.amap(function(i) {return i/2}, function(c) { alert (c); });
Комментарии:
Нет