Lodash - methodOf 方法
語法
_.methodOf(object, [args])
_.method 的相反方法;此方法建立一個函式,在物件的指定路徑處呼叫該方法。任何其他引數都會提供給被呼叫的方法。
引數
object (物件) - 要查詢的物件。
[args] (...*) - 呼叫方法使用的引數。
輸出
(Function) - 返回新的呼叫者函式。
示例
var _ = require('lodash');
var array = _.times(3, _.constant);
var object = { 'a': array, 'b': array, 'c': array };
console.log(_.map(['a[2]', 'c[0]'], _.methodOf(object)));
console.log(_.map([['a', '2'], ['c', '0']], _.methodOf(object)));
將上述程式儲存在 tester.js 中。執行以下命令以執行此程式。
命令
\>node tester.js
輸出
[ 2, 0 ] [ 2, 0 ]
lodash_util.htm
廣告