Lodash - spread 方法



語法

_.spread(func, [start=0])

建立一個函式,該函式透過建立函式和類似於 Function#apply 的一系列引數,來呼叫 func。

引數

  • func(函式) − 在此之上展開引數的函式。

  • [start=0](數字) − 展開的開始位置。

輸出

  • (函式) − 返回新函式。

示例

var _ = require('lodash');

var say = _.spread(function(who, what) {
   return who + ' says ' + what;
});
console.log(say(['Joe', 'Hi']));

將上述程式另存為 tester.js。執行以下命令以執行此程式。

命令

\>node tester.js

輸出

Joe says Hi
lodash_function.htm
廣告
© . All rights reserved.