| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/toString | [Back] [Original] |
Get to know MDN better
function sum(a, b) {
return a + b;
}
console.log(sum.toString());
// : "function sum(a, b) {
// return a + b;
// }"
console.log(Math.abs.toString());
// : "function abs() { [native code] }"
toString()
Function Object toString Object.prototype.toString Function toString
JavaScript toString
this Function toString() TypeError ("Function.prototype.toString called on incompatible object")
Function.prototype.toString.call("foo"); // TypeError
toString() Function.prototype.bind() JavaScript toString()
function someName() { [native code] }
someName [1 + 1]someName1
:
eval()
toString() Function toString() "anonymous" Function("a", "b", "return a + b").toString()
function anonymous(a,b
) {
return a + b
}
function test(fn) {
console.log(fn.toString());
}
function f() {}
class A {
a() {}
}
function* g() {}
test(f); // "function f() {}"
test(A); // "class A { a() {} }"
test(g); // "function* g() {}"
test((a) => a); // "(a) => a"
test({ a() {} }.a); // "a() {}"
test({ *a() {} }.a); // "*a() {}"
test({ [0]() {} }[0]); // "[0]() {}"
test(Object.getOwnPropertyDescriptor({ get a() {} }, "a").get); // "get a() {}"
test(Object.getOwnPropertyDescriptor({ set a(x) {} }, "a").set); // "set a(x) {}"
test(Function.prototype.toString); // "function toString() { [native code] }"
test(function f() {}.bind(0)); // "function () { [native code] }"
test(Function("a", "b")); // function anonymous(a\n) {\nb\n}
Function.prototype.toString() toString() Function eval()
function foo() {
return "bar";
}
console.log(`${foo}`);
// function foo() {
// return "bar";
// }
function foo /* a comment */() {
return "bar";
}
console.log(foo.toString());
// function foo /* a comment */() {
// return "bar";
// }
| ECMAScript 2027 LanguageSpecification # sec-function.prototype.tostring |
| Web Proxy Viewer | New URL | Original Page |