| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/name | [Back] [Original] |
Get to know MDN better
const func1 = function () {};
const object = {
func2: function () {},
};
console.log(func1.name);
// : "func1"
console.log(object.func2.name);
// : "func2"
Function: name | |
|---|---|
:
ES2015 configurable false
name
name
function someFunction() {}
someFunction.name = "otherFunction";
console.log(someFunction.name); // someFunction
name
name
function doSomething() {}
doSomething.name; // "doSomething"
export default "default"
// -- someModule.js --
export default function () {}
// -- main.js --
import someModule from "./someModule.js";
someModule.name; // "default"
Function() "anonymous"
new Function().name; // "anonymous"
name
const someFunction = function someFunctionName() {};
someFunction.name; // "someFunctionName"
function ""
(function () {}).name; // ""
(() => {}).name; // ""
function getFoo() {
return () => {};
}
getFoo().name; // ""
const f = function () {};
const object = {
someMethod: function () {},
};
console.log(f.name); // "f"
console.log(object.someMethod.name); // "someMethod"
let f;
f = () => {};
f.name; // "f"
const [f = () => {}] = [];
f.name; // "f"
const { someMethod: m = () => {} } = {};
m.name; // "m"
function foo(f = () => {}) {
console.log(f.name);
}
foo(); // "f"
class Foo {
static someMethod = () => {};
}
Foo.someMethod.name; // someMethod
const o = {
foo() {},
};
o.foo.name; // "foo";
Function.bind() "bound "
function foo() {}
foo.bind({}).name; // "bound foo"
const o = {
get foo() {
return 1;
},
set foo(x) {},
};
const descriptor = Object.getOwnPropertyDescriptor(o, "foo");
descriptor.get.name; // "get foo"
descriptor.set.name; // "set foo";
obj.constructor.name ()
class Foo {}
Foo.name; // "Foo"
(Symbol)
const sym1 = Symbol("foo");
const sym2 = Symbol();
const o = {
[sym1]() {},
[sym2]() {},
};
o[sym1].name; // "[foo]"
o[sym2].name; // "[]"
(#)
class Foo {
#field = () => {};
#method() {}
getNames() {
console.log(this.#field.name);
console.log(this.#method.name);
}
}
new Foo().getNames();
// "#field"
// "#method"
obj.constructor.name
function Foo() {} // class Foo {}
const fooInstance = new Foo();
console.log(fooInstance.constructor.name); // "Foo"
name()
class Foo {
constructor() {}
static name() {}
}
static name() Foo.name name() fooInstance fooInstance.constructor.name
const fooInstance = new Foo();
console.log(fooInstance.constructor.name); // name() {}
name
class Foo {
static name = 123;
}
console.log(new Foo().constructor.name); // 123
name
Foo.name = "Hello";
console.log(Foo.name); // Foo "name" "Hello" "Foo"
name
:
name JavaScript JavaScript
function Foo() {}
const foo = new Foo();
if (foo.constructor.name === "Foo") {
console.log("'foo' 'Foo' ");
} else {
console.log("");
}
function a() {}
const b = new a();
if (b.constructor.name === "Foo") {
console.log("'foo' 'Foo' ");
} else {
console.log("");
}
"'foo' 'Foo' " else name
| ECMAScript 2027 LanguageSpecification # sec-function-instances-name |
| Web Proxy Viewer | New URL | Original Page |