Underscore.JS - times 方法
语法
_.times(n, iteratee, [context])
times 方法调用 iteratee 函数 n 次。它还将索引传递给 iteratee 函数。请参阅以下示例 −
示例
var _ = require('underscore'); //示例:检查 times 方法是否调用函数 3 次 _.times(3, function(index){console.log(index)});
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
0 1 2