if (!Number.prototype.times) {
Number.prototype.times = function (callback) {
var counter = this
, i;
if (Object.prototype.toString.call(counter) !== '[object Number]') {
throw new Error('Counter in "times" function must be number.');
}
counter = Math.abs(parseInt(counter, 10));
if (counter === 0) {return;}
counter++;
for (i = 1; i < counter; i++) {
callback(i);
}
};
}
console.log('First test');
(0).times(function(i){console.log(i);});
console.log('Second test');
(1).times(function(i){console.log(i);});
console.log('Third test');
(2).times(function(i){console.log(i);});
Комментариев нет:
Отправить комментарий