Package Exports
- function.name-polyfill
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (function.name-polyfill) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Function.name
Overview
A polyfill for the basic functionality of Function.name accessor property in its pre-ES6 form.
Usage
Named function declarations
function hello() {
/* ... */
}
console.log(hello.name); // "hello"Named function expressions
var fn = function foo() {
/* ... */
};
console.log(fn.name); // "foo"Browser Compatibility
Most modern browsers have already supported this basic functionality for quite some time but this polyfill will apply to at least the following:
- IE
>=9 <12 - Chrome
<33
For IE <9, you can still use fn._name() instead.
Caveats
Pre-ES6 Form
- In short, this means that this polyfilled
nameaccessor property can provide you with the name of a named function definition (either a named function declaration or a named function expression). - Unlike its enhanced ES6 form, this polyfilled
nameaccessor property is also intentionally marked as non-configurable to keep it better aligned with other browsers with a similar support level.
Chrome <5
- When polyfilling for Chrome
<5, the accessor property will be enumerable and configurable due to having to implement it usingObject.prototype.__defineGetter__instead ofObject.defineProperty.