šŸ•·ļø Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 6 (from laksa031)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ā„¹ļø Skipped - page is already crawled

šŸ“„
INDEXABLE
āœ…
CRAWLED
8 days ago
šŸ¤–
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.3 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name
Last Crawled2026-04-08 23:06:42 (8 days ago)
First Indexed2020-09-08 09:00:48 (5 years ago)
HTTP Status Code200
Meta TitleFunction.name - JavaScript
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
A Function object's read-only name property indicates the function's name as specified when it was created, or it may be rather anonymous or '' (an empty string) for functions created anonymously. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request. Property attributes of Function.name Writable no Enumerable no Configurable yes Note that in non-standard, pre-ES2015 implementations the configurable attribute was false as well. JavaScript compressors and minifiers Warning: Be careful when using Function.name and source code transformations, such as those carried out by JavaScript compressors (minifiers) or obfuscators. These tools are often used as part of a JavaScript build pipeline to reduce the size of a program prior to deploying it to production. Such transformations often change a function's name at build-time. Source code such as: function Foo() {}; let foo = new Foo(); if (foo.constructor.name === 'Foo') { console.log("'foo' is an instance of 'Foo'"); } else { console.log('Oops!'); } may be compressed to: function a() {}; let b = new a(); if (b.constructor.name === 'Foo') { console.log("'foo' is an instance of 'Foo'"); } else { console.log('Oops!'); } In the uncompressed version, the program runs into the truthy-branch and logs "'foo' is an instance of 'Foo'" . Whereas, in the compressed version it behaves differently, and runs into the else-branch. If you rely on Function.name , like in the example above, make sure your build pipeline doesn't change function names, or don't assume a function to have a particular name. Examples Function statement name The name property returns the name of a function statement. function doSomething() {} doSomething.name; // "doSomething" Function constructor name Functions created with the syntax new Function(...) or just Function(...) create Function objects and their name is "anonymous". (new Function).name; // "anonymous" Anonymous function expression Anonymous function expressions that were created using the keyword function or arrow functions would have "" (an empty string) as their name. (function() {}).name; // "" (() => {}).name; // "" Inferred function names Variables and methods can infer the name of an anonymous function from its syntactic position (new in ECMAScript 2015). let f = function() {}; let object = { someMethod: function() {} }; console.log(f.name); // "f" console.log(object.someMethod.name); // "someMethod" You can define a function with a name in a function expression : let object = { someMethod: function object_someMethod() {} }; console.log(object.someMethod.name); // logs "object_someMethod" try { object_someMethod } catch(e) { console.log(e); } // ReferenceError: object_someMethod is not defined The name property is read-only and cannot be changed by the assigment operator: Example below contradicts with what is said at the beginning of this section and doesn't work as described. let object = { // anonymous someMethod: function() {} }; object.someMethod.name = 'otherMethod'; console.log(object.someMethod.name); // someMethod To change it, use Object.defineProperty() . Shorthand method names var o = { foo(){} }; o.foo.name; // "foo"; Bound function names Function.bind() produces a function whose name is "bound " plus the function name. function foo() {}; foo.bind({}).name; // "bound foo" Function names for getters and setters When using get and set accessor properties, "get" or "set" will appear in the function name. let o = { get foo(){}, set foo(x){} }; var descriptor = Object.getOwnPropertyDescriptor(o, "foo"); descriptor.get.name; // "get foo" descriptor.set.name; // "set foo"; Function names in classes You can use obj.constructor.name to check the "class" of an object (but be sure to read the warnings below): function Foo() {} // ES2015 Syntax: class Foo {} var fooInstance = new Foo(); console.log(fooInstance.constructor.name); // logs "Foo" Warning: The script interpreter will set the built-in Function.name property only if a function does not have an own property called name (see section 9.2.11 of the ECMAScript2015 Language Specification ). However, ES2015 specifies the static keyword such that static methods will be set as OwnProperty of the class constructor function (ECMAScript2015, 14.5.14.21.b + 12.2.6.9 ). Therefore we can't obtain the class name for virtually any class with a static method property name() : class Foo { constructor() {} static name() {} } With a static name() method Foo.name no longer holds the actual class name but a reference to the name() function object. Above class definition in ES2015 syntax will behave in Chrome or Firefox similar to the following snippet in ES5 syntax: function Foo() {} Object.defineProperty(Foo, 'name', { writable: true }); Foo.name = function() {}; Trying to obtain the class of fooInstance via fooInstance.constructor.name won't give us the class name at all but a reference to the static class method. Example: let fooInstance = new Foo(); console.log(fooInstance.constructor.name); // logs function name() You may also see from the ES5 syntax example that in Chrome or Firefox our static definition of Foo.name becomes writable . The built-in definition in the absence of a custom static definition is read-only : Foo.name = 'Hello'; console.log(Foo.name); // logs "Hello" if class Foo has a static name() property but "Foo" if not. Therefore you may not rely on the built-in Function.name property to always hold a class's name. Symbols as function names If a Symbol is used a function name and the symbol has a description, the method's name is the description in square brackets. let sym1 = Symbol("foo"); let sym2 = Symbol(); let o = { [sym1]: function(){}, [sym2]: function(){} }; o[sym1].name; // "[foo]" o[sym2].name; // "" Specifications Specification ECMAScript (ECMA-262) The definition of 'name' in that specification. Browser compatibility The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. Desktop Mobile Server Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js name Chrome Full support 15 Edge Full support 14 Firefox Full support 1 IE No support No Opera Full support 10.5 Safari Full support 6 WebView Android Full support 1 Chrome Android Full support 18 Firefox Android Full support 4 Opera Android Full support 11 Safari iOS Full support 6 Samsung Internet Android Full support 1.0 nodejs Full support Yes Configurable: true Chrome Full support 43 Edge Full support 14 Firefox Full support 38 IE No support No Opera Full support 30 Safari No support No WebView Android Full support 43 Chrome Android Full support 43 Firefox Android Full support 38 Opera Android Full support 30 Safari iOS No support No Samsung Internet Android Full support 4.0 nodejs ? Inferred names on anonymous functions Chrome Full support 51 Edge Partial support 14 Notes Partial support 14 Notes Notes Names for functions defined in a dictionary are properly assigned; however, anonymous functions defined on a var/let variable assignment have blank names. Firefox Full support 53 IE No support No Opera Full support 38 Safari Full support 10 WebView Android Full support 51 Chrome Android Full support 51 Firefox Android Full support 53 Opera Android Full support 41 Safari iOS Full support 10 Samsung Internet Android Full support 5.0 nodejs ? Legend Full support Full support Partial support Partial support No support No support Compatibility unknown Compatibility unknown See implementation notes. See implementation notes. See also Function
Markdown
- [Skip to main content](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#content) [![UDN Web Docs: MDN Backup](https://udn.realityripple.com/static/img/web-docs-black.png)](https://udn.realityripple.com/) - Technologies - [Technologies Overview](https://udn.realityripple.com/docs/Web) - [XUL](https://udn.realityripple.com/docs/Archive/Mozilla/XUL) - [HTML](https://udn.realityripple.com/docs/Web/HTML) - [CSS](https://udn.realityripple.com/docs/Web/CSS) - [JavaScript](https://udn.realityripple.com/docs/Web/JavaScript) - [XPCOM](https://udn.realityripple.com/docs/Mozilla/Tech/XPCOM) - [Graphics](https://udn.realityripple.com/docs/Web/Guide/Graphics) - [HTTP](https://udn.realityripple.com/docs/Web/HTTP) - [APIs / DOM](https://udn.realityripple.com/docs/Web/API) - [MathML](https://udn.realityripple.com/docs/Web/MathML) - References & Guides - [Learn web development](https://udn.realityripple.com/docs/Learn) - [Tutorials](https://udn.realityripple.com/docs/Web/Tutorials) - [References](https://udn.realityripple.com/docs/Web/Reference) - [Developer Guides](https://udn.realityripple.com/docs/Web/Guide) - [Accessibility](https://udn.realityripple.com/docs/Web/Accessibility) - [Game development](https://udn.realityripple.com/docs/Games) - [...more docs](https://udn.realityripple.com/docs/Web) - Additional Resources - [Archive](https://udn.realityripple.com/docs/Archive) - [UXP Homepage 🌐](http://thereisonlyxul.org/) - [Pale Moon on GitHub 🌐](https://github.com/RealityRipple/Pale-Moon/) - [UXP on GitHub 🌐](https://github.com/RealityRipple/UXP/) - [Pale Moon Forum 🌐](https://forum.palemoon.org/) - [Support Pale Moon 🌐](https://www.palemoon.org/donations.shtml) - [Support the Backup](https://realityripple.com/donate.php?itm=UDN)[Additional Details](https://realityripple.com/fossil.php) # Function.name 1. [See Web technology for developers](https://udn.realityripple.com/docs/Web) 2. [See JavaScript](https://udn.realityripple.com/docs/Web/JavaScript) 3. [See JavaScript reference](https://udn.realityripple.com/docs/Web/JavaScript/Reference) 4. [See Standard built-in objects](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects) 5. [See Function](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function) 6. [Function.name](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name) ## On this Page Jump to section - [JavaScript compressors and minifiers](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#JavaScript_compressors_and_minifiers) - [Examples](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#Examples) - [Specifications](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#Specifications) - [Browser compatibility](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#Browser_compatibility) - [See also](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#See_also) - [Related topics](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name#sidebar-quicklinks) A [`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function) object's read-only `name` property indicates the function's name as specified when it was created, or it may be rather `anonymous` or `''`(an empty string) for functions created anonymously. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <https://github.com/mdn/interactive-examples> and send us a pull request. | Property attributes of `Function.name` | | |---|---| | Writable | no | | Enumerable | no | | Configurable | yes | Note that in non-standard, pre-ES2015 implementations the `configurable` attribute was `false` as well. ## JavaScript compressors and minifiers **Warning:** Be careful when using `Function.name` and source code transformations, such as those carried out by JavaScript compressors (minifiers) or obfuscators. These tools are often used as part of a JavaScript build pipeline to reduce the size of a program prior to deploying it to production. Such transformations often change a function's name at build-time. Source code such as: ``` function Foo() {}; let foo = new Foo(); if (foo.constructor.name === 'Foo') { console.log("'foo' is an instance of 'Foo'"); } else { console.log('Oops!'); } ``` may be compressed to: ``` function a() {}; let b = new a(); if (b.constructor.name === 'Foo') { console.log("'foo' is an instance of 'Foo'"); } else { console.log('Oops!'); } ``` In the uncompressed version, the program runs into the truthy-branch and logs `"'foo' is an instance of 'Foo'"`. Whereas, in the compressed version it behaves differently, and runs into the else-branch. If you rely on `Function.name`, like in the example above, make sure your build pipeline doesn't change function names, or don't assume a function to have a particular name. ## Examples ### Function statement name The `name` property returns the name of a function statement. ``` function doSomething() {} doSomething.name; // "doSomething" ``` ### Function constructor name Functions created with the syntax `new Function(...)` or just `Function(...)` create [`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function) objects and their name is "anonymous". ``` (new Function).name; // "anonymous" ``` ### Anonymous function expression Anonymous function expressions that were created using the keyword `function` or arrow functions would have `""`(an empty string) as their name. ``` (function() {}).name; // "" (() => {}).name; // "" ``` ### Inferred function names Variables and methods can infer the name of an anonymous function from its syntactic position (new in ECMAScript 2015). ``` let f = function() {}; let object = { someMethod: function() {} }; console.log(f.name); // "f" console.log(object.someMethod.name); // "someMethod" ``` You can define a function with a name in a [function expression](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Operators/function): ``` let object = { someMethod: function object_someMethod() {} }; console.log(object.someMethod.name); // logs "object_someMethod" try { object_someMethod } catch(e) { console.log(e); } // ReferenceError: object_someMethod is not defined ``` The name property is read-only and cannot be changed by the assigment operator: Example below contradicts with what is said at the beginning of this section and doesn't work as described. ``` let object = { // anonymous someMethod: function() {} }; object.someMethod.name = 'otherMethod'; console.log(object.someMethod.name); // someMethod ``` To change it, use [`Object.defineProperty()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). ### Shorthand method names ``` var o = { foo(){} }; o.foo.name; // "foo"; ``` ### Bound function names [`Function.bind()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) produces a function whose name is "bound " plus the function name. ``` function foo() {}; foo.bind({}).name; // "bound foo" ``` ### Function names for getters and setters When using `get` and `set` accessor properties, "get" or "set" will appear in the function name. ``` let o = { get foo(){}, set foo(x){} }; var descriptor = Object.getOwnPropertyDescriptor(o, "foo"); descriptor.get.name; // "get foo" descriptor.set.name; // "set foo"; ``` ### Function names in classes You can use `obj.constructor.name` to check the "class" of an object (but be sure to read the warnings below): ``` function Foo() {} // ES2015 Syntax: class Foo {} var fooInstance = new Foo(); console.log(fooInstance.constructor.name); // logs "Foo" ``` **Warning:** The script interpreter will set the built-in `Function.name` property only if a function does not have an own property called *name* (see section [9\.2.11 of the ECMAScript2015 Language Specification](https://www.ecma-international.org/ecma-262/6.0/#sec-setfunctionname)). However, ES2015 specifies the *static* keyword such that static methods will be set as OwnProperty of the class constructor function (ECMAScript2015, [14\.5.14.21.b](https://www.ecma-international.org/ecma-262/6.0/#sec-runtime-semantics-classdefinitionevaluation) + [12\.2.6.9](https://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer-runtime-semantics-propertydefinitionevaluation)). Therefore we can't obtain the class name for virtually any class with a static method property `name()`: ``` class Foo { constructor() {} static name() {} } ``` With a `static name()` method `Foo.name` no longer holds the actual class name but a reference to the `name()` function object. Above class definition in ES2015 syntax will behave in Chrome or Firefox similar to the following snippet in ES5 syntax: ``` function Foo() {} Object.defineProperty(Foo, 'name', { writable: true }); Foo.name = function() {}; ``` Trying to obtain the class of `fooInstance` via `fooInstance.constructor.name` won't give us the class name at all but a reference to the static class method. Example: ``` let fooInstance = new Foo(); console.log(fooInstance.constructor.name); // logs function name() ``` You may also see from the ES5 syntax example that in Chrome or Firefox our static definition of `Foo.name` becomes *writable*. The built-in definition in the absence of a custom static definition is *read-only*: ``` Foo.name = 'Hello'; console.log(Foo.name); // logs "Hello" if class Foo has a static name() property but "Foo" if not. ``` Therefore you may not rely on the built-in `Function.name` property to always hold a class's name. ### Symbols as function names If a [`Symbol`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Symbol) is used a function name and the symbol has a description, the method's name is the description in square brackets. ``` let sym1 = Symbol("foo"); let sym2 = Symbol(); let o = { [sym1]: function(){}, [sym2]: function(){} }; o[sym1].name; // "[foo]" o[sym2].name; // "" ``` ## Specifications | Specification | |---| | [ECMAScript (ECMA-262) The definition of 'name' in that specification.](https://tc39.es/ecma262/#sec-function-instances-name) | ## Browser compatibility The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <https://github.com/mdn/browser-compat-data> and send us a pull request. | | | | | | | | | | | | | | | |---|---|---|---|---|---|---|---|---|---|---|---|---|---| | | Desktop | Mobile | Server | | | | | | | | | | | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js | | `name` | ChromeFull support 15 | EdgeFull support 14 | FirefoxFull support 1 | IENo support No | OperaFull support 10.5 | SafariFull support 6 | WebView AndroidFull support 1 | Chrome AndroidFull support 18 | Firefox AndroidFull support 4 | Opera AndroidFull support 11 | Safari iOSFull support 6 | Samsung Internet AndroidFull support 1.0 | nodejsFull support Yes | | Configurable: true | ChromeFull support 43 | EdgeFull support 14 | FirefoxFull support 38 | IENo support No | OperaFull support 30 | SafariNo support No | WebView AndroidFull support 43 | Chrome AndroidFull support 43 | Firefox AndroidFull support 38 | Opera AndroidFull support 30 | Safari iOSNo support No | Samsung Internet AndroidFull support 4.0 | nodejs? | | Inferred names on anonymous functions | ChromeFull support 51 | EdgePartial support14NotesPartial support 14 Notes Notes Names for functions defined in a dictionary are properly assigned; however, anonymous functions defined on a var/let variable assignment have blank names. | FirefoxFull support 53 | IENo support No | OperaFull support 38 | SafariFull support 10 | WebView AndroidFull support 51 | Chrome AndroidFull support 51 | Firefox AndroidFull support 53 | Opera AndroidFull support 41 | Safari iOSFull support 10 | Samsung Internet AndroidFull support 5.0 | nodejs? | ### Legend Full support Full support Partial support Partial support No support No support Compatibility unknown Compatibility unknown See implementation notes. See implementation notes. ## See also - [`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function) Related Topics 1. **[Standard built-in objects](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects)** 2. **[`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function)** 3. [**Properties**](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name) 1. [`Function.arguments`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/arguments) 2. [`Function.caller`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/caller) 3. [`Function.displayName`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/displayName) 4. [`Function.length`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/length) 5. *`Function.name`* 4. [**Methods**](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name) 1. [`Function.prototype.apply()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/apply) 2. [`Function.prototype.bind()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) 3. [`Function.prototype.call()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/call) 4. ~~[`Function.prototype.toSource()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/toSource)~~ 5. [`Function.prototype.toString()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/toString) 5. **Inheritance:** 6. **[`Object`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object)** 7. [**Properties**](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name) 1. [`Object.prototype.__proto__`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) 2. [`Object.prototype.constructor`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) 8. [**Methods**](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/name) 1. [`Object.prototype.__defineGetter__()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) 2. [`Object.prototype.__defineSetter__()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__) 3. [`Object.prototype.__lookupGetter__()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__) 4. [`Object.prototype.__lookupSetter__()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__) 5. [`Object.prototype.hasOwnProperty()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty) 6. [`Object.prototype.isPrototypeOf()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf) 7. [`Object.prototype.propertyIsEnumerable()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable) 8. [`Object.prototype.toLocaleString()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString) 9. ~~[`Object.prototype.toSource()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/toSource)~~ 10. [`Object.prototype.toString()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/toString) 11. [`Object.prototype.valueOf()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) 12. [`Object.setPrototypeOf()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf) [MDN Web Docs](https://udn.realityripple.com/) © 2005-2020 [Mozilla and individual contributors](https://developer.mozilla.org/docs/MDN/About#Copyrights_and_licenses). Content is available under [CC BY-SA-2.5](https://realityripple.com/license.php?l=CC-BY-SA-2.5). Backup generated August, 2020 by [RealityRipple Software](https://realityripple.com/). [Report a Broken Link]() - [~~Terms~~]("There are no terms and conditions for using this backup.") - [Privacy](https://realityripple.com/privacy.php) - [~~Cookies~~]("There are no cookies used in this backup.")
Readable Markdown
A [`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function) object's read-only `name` property indicates the function's name as specified when it was created, or it may be rather `anonymous` or `''`(an empty string) for functions created anonymously. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <https://github.com/mdn/interactive-examples> and send us a pull request. | Property attributes of `Function.name` | | |---|---| | Writable | no | | Enumerable | no | | Configurable | yes | Note that in non-standard, pre-ES2015 implementations the `configurable` attribute was `false` as well. ## JavaScript compressors and minifiers **Warning:** Be careful when using `Function.name` and source code transformations, such as those carried out by JavaScript compressors (minifiers) or obfuscators. These tools are often used as part of a JavaScript build pipeline to reduce the size of a program prior to deploying it to production. Such transformations often change a function's name at build-time. Source code such as: ``` function Foo() {}; let foo = new Foo(); if (foo.constructor.name === 'Foo') { console.log("'foo' is an instance of 'Foo'"); } else { console.log('Oops!'); } ``` may be compressed to: ``` function a() {}; let b = new a(); if (b.constructor.name === 'Foo') { console.log("'foo' is an instance of 'Foo'"); } else { console.log('Oops!'); } ``` In the uncompressed version, the program runs into the truthy-branch and logs `"'foo' is an instance of 'Foo'"`. Whereas, in the compressed version it behaves differently, and runs into the else-branch. If you rely on `Function.name`, like in the example above, make sure your build pipeline doesn't change function names, or don't assume a function to have a particular name. ## Examples ### Function statement name The `name` property returns the name of a function statement. ``` function doSomething() {} doSomething.name; // "doSomething" ``` ### Function constructor name Functions created with the syntax `new Function(...)` or just `Function(...)` create [`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function) objects and their name is "anonymous". ``` (new Function).name; // "anonymous" ``` ### Anonymous function expression Anonymous function expressions that were created using the keyword `function` or arrow functions would have `""`(an empty string) as their name. ``` (function() {}).name; // "" (() => {}).name; // "" ``` ### Inferred function names Variables and methods can infer the name of an anonymous function from its syntactic position (new in ECMAScript 2015). ``` let f = function() {}; let object = { someMethod: function() {} }; console.log(f.name); // "f" console.log(object.someMethod.name); // "someMethod" ``` You can define a function with a name in a [function expression](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Operators/function): ``` let object = { someMethod: function object_someMethod() {} }; console.log(object.someMethod.name); // logs "object_someMethod" try { object_someMethod } catch(e) { console.log(e); } // ReferenceError: object_someMethod is not defined ``` The name property is read-only and cannot be changed by the assigment operator: Example below contradicts with what is said at the beginning of this section and doesn't work as described. ``` let object = { // anonymous someMethod: function() {} }; object.someMethod.name = 'otherMethod'; console.log(object.someMethod.name); // someMethod ``` To change it, use [`Object.defineProperty()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). ### Shorthand method names ``` var o = { foo(){} }; o.foo.name; // "foo"; ``` ### Bound function names [`Function.bind()`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) produces a function whose name is "bound " plus the function name. ``` function foo() {}; foo.bind({}).name; // "bound foo" ``` ### Function names for getters and setters When using `get` and `set` accessor properties, "get" or "set" will appear in the function name. ``` let o = { get foo(){}, set foo(x){} }; var descriptor = Object.getOwnPropertyDescriptor(o, "foo"); descriptor.get.name; // "get foo" descriptor.set.name; // "set foo"; ``` ### Function names in classes You can use `obj.constructor.name` to check the "class" of an object (but be sure to read the warnings below): ``` function Foo() {} // ES2015 Syntax: class Foo {} var fooInstance = new Foo(); console.log(fooInstance.constructor.name); // logs "Foo" ``` **Warning:** The script interpreter will set the built-in `Function.name` property only if a function does not have an own property called *name* (see section [9\.2.11 of the ECMAScript2015 Language Specification](https://www.ecma-international.org/ecma-262/6.0/#sec-setfunctionname)). However, ES2015 specifies the *static* keyword such that static methods will be set as OwnProperty of the class constructor function (ECMAScript2015, [14\.5.14.21.b](https://www.ecma-international.org/ecma-262/6.0/#sec-runtime-semantics-classdefinitionevaluation) + [12\.2.6.9](https://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer-runtime-semantics-propertydefinitionevaluation)). Therefore we can't obtain the class name for virtually any class with a static method property `name()`: ``` class Foo { constructor() {} static name() {} } ``` With a `static name()` method `Foo.name` no longer holds the actual class name but a reference to the `name()` function object. Above class definition in ES2015 syntax will behave in Chrome or Firefox similar to the following snippet in ES5 syntax: ``` function Foo() {} Object.defineProperty(Foo, 'name', { writable: true }); Foo.name = function() {}; ``` Trying to obtain the class of `fooInstance` via `fooInstance.constructor.name` won't give us the class name at all but a reference to the static class method. Example: ``` let fooInstance = new Foo(); console.log(fooInstance.constructor.name); // logs function name() ``` You may also see from the ES5 syntax example that in Chrome or Firefox our static definition of `Foo.name` becomes *writable*. The built-in definition in the absence of a custom static definition is *read-only*: ``` Foo.name = 'Hello'; console.log(Foo.name); // logs "Hello" if class Foo has a static name() property but "Foo" if not. ``` Therefore you may not rely on the built-in `Function.name` property to always hold a class's name. ### Symbols as function names If a [`Symbol`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Symbol) is used a function name and the symbol has a description, the method's name is the description in square brackets. ``` let sym1 = Symbol("foo"); let sym2 = Symbol(); let o = { [sym1]: function(){}, [sym2]: function(){} }; o[sym1].name; // "[foo]" o[sym2].name; // "" ``` ## Specifications | Specification | |---| | [ECMAScript (ECMA-262) The definition of 'name' in that specification.](https://tc39.es/ecma262/#sec-function-instances-name) | ## Browser compatibility The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <https://github.com/mdn/browser-compat-data> and send us a pull request. | | | | | | | | | | | | | | | |---|---|---|---|---|---|---|---|---|---|---|---|---|---| | | Desktop | Mobile | Server | | | | | | | | | | | | | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js | | `name` | ChromeFull support 15 | EdgeFull support 14 | FirefoxFull support 1 | IENo support No | OperaFull support 10.5 | SafariFull support 6 | WebView AndroidFull support 1 | Chrome AndroidFull support 18 | Firefox AndroidFull support 4 | Opera AndroidFull support 11 | Safari iOSFull support 6 | Samsung Internet AndroidFull support 1.0 | nodejsFull support Yes | | Configurable: true | ChromeFull support 43 | EdgeFull support 14 | FirefoxFull support 38 | IENo support No | OperaFull support 30 | SafariNo support No | WebView AndroidFull support 43 | Chrome AndroidFull support 43 | Firefox AndroidFull support 38 | Opera AndroidFull support 30 | Safari iOSNo support No | Samsung Internet AndroidFull support 4.0 | nodejs? | | Inferred names on anonymous functions | ChromeFull support 51 | EdgePartial support14NotesPartial support 14 Notes Notes Names for functions defined in a dictionary are properly assigned; however, anonymous functions defined on a var/let variable assignment have blank names. | FirefoxFull support 53 | IENo support No | OperaFull support 38 | SafariFull support 10 | WebView AndroidFull support 51 | Chrome AndroidFull support 51 | Firefox AndroidFull support 53 | Opera AndroidFull support 41 | Safari iOSFull support 10 | Samsung Internet AndroidFull support 5.0 | nodejs? | ### Legend Full support Full support Partial support Partial support No support No support Compatibility unknown Compatibility unknown See implementation notes. See implementation notes. ## See also - [`Function`](https://udn.realityripple.com/docs/Web/JavaScript/Reference/Global_Objects/Function)
Shard6 (laksa)
Root Hash16997887161487951006
Unparsed URLcom,realityripple!udn,/docs/Web/JavaScript/Reference/Global_Objects/Function/name s443