Lodash - delay方法



語法

_.delay(func, wait, [args])

在等待毫秒後呼叫func。當呼叫func時,任何其他引數都會提供給func。

引數

  • func(函式) - 要延遲的函式。

  • 等待(數字) - 呼叫延遲的毫秒數。

  • [args](...*) - 用來呼叫func的引數。

輸出

  • (數字) - 返回計時器id。

示例

var _ = require('lodash');
var startTimestamp = new Date().getTime();

var add = function(a,b) {
   console.log(a + b);
   var endTimestamp = new Date().getTime();
   console.log(((endTimestamp - startTimestamp)) + ' ms');   
};
_.delay(add, 1000, 5, 10);

將以上程式儲存在tester.js中。執行下列命令執行此程式。

命令

\>node tester.js

輸出

15
1024 ms
lodash_function.htm
廣告
© . All rights reserved.