打印

使用Number的times方法实现循环

使用Number的times方法实现循环

在javascript中我们经常使用for实现循环,如
复制内容到剪贴板
代码:
var t = 3;
for(var i = 0; i < t; i++) {
    alert(i);
}
在rails中,默认引入了prototype,我们可以换一种写法
复制内容到剪贴板
代码:
var t = 3;
t.times(function(n) {
    alert(n);
});
prototype对javascript的number进行了扩展,支持ruby方式的times循环了
First they ignore you, then they laugh at you, then they fight you, then you win.

TOP