function.prototype.name
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
call-bind | 1.0.7 | 21.6 kB | MIT | prod | |
define-properties | 1.2.1 | 5.08 kB | MIT | prod | |
es-abstract | 1.23.3 | 1 B | MIT | prod | |
functions-have-names | 1.2.3 | 5.86 kB | MIT | prod |
Function.prototype.name is an ES2015 spec-compliant shim that adds functionality to the existing JavaScript Function.prototype object. It aims to fill in gaps in JavaScript environments that might not natively support the function name property by providing a polyfill. This property typically returns the name of the function, as a string value. Remember, for this shim to work, your environment must support ES5, specifically ES5 getters.
When it comes to implementation, first, you need to install the "function.prototype.name" package using npm, which can be done using the command npm install function.prototype.name
. Then you can require it in your JavaScript file like so:
var functionName = require('function.prototype.name');
var assert = require('assert');
Next, you can use it standalone or you can invoke the "shim" method if Function.prototype.name is unavailable in your environment. For example:
assert.equal(functionName(function foo() {}), 'foo');
functionName.shim();
assert.equal(function foo() {}.name, 'foo');
In the above example, the ‘functionName’ function is used to get the name of a function (in this case, 'foo'). Then, the shim
method is called to patch lack of native support for Function.prototype.name.
The documentation for function.prototype.name is included in the README file on the package's GitHub repository. The URL for the repository is git://github.com/es-shims/Function.prototype.name.git. Other relevant information about the API, including the spec it complies with, can be found at https://www.ecma-international.org/ecma-262/6.0/#sec-get-regexp.prototype.flags. Moreover, the package complies with the es-shim API interface, documented at https://github.com/es-shims/api.