Lodash partial method
语法
_.partial(func, [partials])
Creates a function that invokes func with partials prepended to the arguments it receives. This method is like _.bind except it does not alter the this binding.
参数
func (Function) − The function to partially apply arguments to.
[partials] (...*) − The arguments to be partially applied.
输出
(Function) − Returns the new partially applied function.
实例
var _ = require('lodash');
var divide = function(a, b) { return b / a};
var divideBy5 = _.partial(divide, 5);
var result = divideBy5(10);
console.log(result);
var divisionOf10 = _.partial(divide, _, 10)
result = divisionOf10(5)
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出