Created
January 18, 2016 17:14
-
-
Save triacontane/5cbf02c04abdfb7fd735 to your computer and use it in GitHub Desktop.
指定した回数分処理を繰り返す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number.prototype.times = function(handler) { | |
var i = 0; while(i < this) handler.call(this, i++); | |
}; | |
Number(4).times(function(i) { | |
console.log(i) | |
}.bind(this)); | |
// 0 | |
// 1 | |
// 2 | |
// 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment