util-arity

2018-12-07 admin

util-arity是什么

什么是util-arity,Set the length of a function.

util-arity使用教程帮助文档

Arity

NPM version NPM downloads Build status Test coverage Greenkeeper badge

Set a functions arity (the argument count) by proxying function calls.

P.S. If you don’t care about this and want to receive the exact arity of function arguments, use nary. It uses function invocation over .apply to proxy arguments.

Why would I use this?

You probably won’t. The reason it needs to exist is for functional utilities and backward compatibility with user expectations. Many modules use function arity to decide how the function should behave (e.g. middleware in express or callbacks in mocha).

Installation

npm install util-arity --save

Usage

var fn = function () {};
var arity = require('util-arity');

var oneArg = arity(1, fn);
var twoArgs = arity(2, fn);
var threeArgs = arity(3, fn);

oneArgs.length; //=> 1
twoArgs.length; //=> 2
threeArgs.length; //=> 3

TypeScript

The typings for this project are available for node module resolution with TypeScript.

License

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-47494.html

文章标题:util-arity

回到顶部