Lodash _.arity()方法r返回一个新函数,它等效于的给定的函数,除了新函数的长度属性等于参数个数。这确实不将函数限制为使用该数量的参数。它的唯一的影响是报告的长度。
用法:
_.arity( numberOfArgs, fun )
参数:该方法采用上面列出的和下面讨论的两个参数。
- numberOfArgs:此参数带有一个数字,该数字表示该方法将采用的参数数量。
- fun:这是给定的函数。
返回值:它返回一个新函数。
注意:要执行以下示例,必须使用此命令提示符安装lodash-contrib库,并执行以下命令。
npm install lodash-contrib
范例1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Function
function fun(){
return "GeeksforGeeks";
}
var gfgFunc = _.arity(4,fun);
console.log("Length of function is:",
gfgFunc.length);
console.log("Function content:",
gfgFunc());
输出:
Length of function is:4 Function content:GeeksforGeeks
范例2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Function
function fun(){
return arguments[0]*10;
}
var gfgFunc = _.arity(4,fun);
console.log("Length of function is:",
gfgFunc.length);
console.log("Function content:",
gfgFunc(10));
输出:
Length of function is:4 Function content:100
相关用法
- underscore.js _.arity()用法及代码示例
- Lodash _.method()用法及代码示例
- Lodash _.sneq()用法及代码示例
- Lodash _.toQuery()用法及代码示例
- Lodash _.uniqWith()用法及代码示例
- Lodash _.xorWith()用法及代码示例
- Lodash _.head()用法及代码示例
- Lodash _.remove()用法及代码示例
- Lodash _.pullAt()用法及代码示例
- Lodash _.pullAll()用法及代码示例
- Lodash _.pull()用法及代码示例
- Lodash _.nth()用法及代码示例
- Lodash _.takeRight()用法及代码示例
- Lodash _.take()用法及代码示例
- Lodash _.sortedLastIndex()用法及代码示例
- Lodash _.fromPairs()用法及代码示例
- Lodash _.differenceWith()用法及代码示例
- Lodash _.castArray()用法及代码示例
- Lodash _.cloneDeep()用法及代码示例
- Lodash _.clone()用法及代码示例
- Lodash _.sampleSize()用法及代码示例
- Lodash _.find()用法及代码示例
- Lodash _.zipWith()用法及代码示例
- Lodash _.zipObject()用法及代码示例
注:本文由纯净天空筛选整理自taran910大神的英文原创作品 Lodash _.arity() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。