caoge c760052ff9 机车状态修改 | преди 8 месеца | |
---|---|---|
.. | ||
.github | преди 8 месеца | |
.eslintrc | преди 8 месеца | |
CHANGELOG.md | преди 8 месеца | |
LICENSE | преди 8 месеца | |
README.md | преди 8 месеца | |
index.js | преди 8 месеца | |
package.json | преди 8 месеца |
Set a function’s name.
Arguments:
fn
: the functionname
: the new nameloose
: Optional. If true, and the name fails to be set, do not throw. Default false.Returns fn
.
var setFunctionName = require('set-function-name');
var assert = require('assert');
const obj = {
concise() {},
arrow: () => {},
named: function named() {},
anon: function () {},
};
assert.equal(obj.concise.name, 'concise');
assert.equal(obj.arrow.name, 'arrow');
assert.equal(obj.named.name, 'named');
assert.equal(obj.anon.name, 'anon');
assert.equal(setFunctionName(obj.concise, 'brief'), obj.concise);
assert.equal(setFunctionName(obj.arrow, 'pointy'), obj.arrow);
assert.equal(setFunctionName(obj.named, ''), obj.named);
assert.equal(setFunctionName(obj.anon, 'anonymous'), obj.anon);
assert.equal(obj.concise.name, 'brief');
assert.equal(obj.arrow.name, 'pointy');
assert.equal(obj.named.name, '');
assert.equal(obj.anon.name, 'anonymous');