Lodash - rest 方法
語法
_.rest(func, [start=func.length-1])
建立一個函式,該函式將使用建立的函式和作為陣列提供的 start 和更高位置處的引數來呼叫 func。
引數
func (函式) − 要應用剩餘引數的函式。
[start=func.length-1] (數字) − 剩餘引數的起始位置。
輸出
(函式) − 返回新函式。
示例
var _ = require('lodash');
var say = _.rest(function(what, names) {
return what + ' ' + _.initial(names).join(', ') + (_.size(names) > 1 ? ' & ' : '') + _.last(names);
});
console.log(say('Hello', 'Joe', 'Tom', 'Julie'));
將上述程式儲存到 tester.js 中。執行以下命令來執行此程式。
命令
\>node tester.js
輸出
Hello Joe, Tom & Julie
lodash_function.htm
廣告