Lodash - nthArg 方法
語法
_.nthArg([n=0])
建立一個獲取位於索引 n 處的引數的函式。如果 n 為負值,則返回從末尾開始的第 n 個引數。
引數
[n=0] (數字) − 要返回的引數的索引。
輸出
(函式) − 返回新的直通函式。
示例
var _ = require('lodash');
var func = _.nthArg(1);
console.log(func('a', 'b', 'c', 'd'));
func = _.nthArg(2);
console.log(func('a', 'b', 'c', 'd'));
將上述程式儲存在 **tester.js** 中。執行以下命令以執行此程式。
命令
\>node tester.js
輸出
b c
lodash_util.htm
廣告