| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 4.
Symbol.toStringTag @@toStringTag . Object.prototype.toString() this .
class ValidatorClass {
get [Symbol.toStringTag]() {
return "Validator";
}
}
console.log(Object.prototype.toString.call(new ValidatorClass()));
// Expected output: "[object Validator]"
@@toStringTag.
Property attributes of Symbol.toStringTag | |
|---|---|
Symbol.toStringTag toString() . Object.prototype.toString()() .
Object.prototype.toString.call("foo"); // "[object String]"
Object.prototype.toString.call([1, 2]); // "[object Array]"
Object.prototype.toString.call(3); // "[object Number]"
Object.prototype.toString.call(true); // "[object Boolean]"
Object.prototype.toString.call(undefined); // "[object Undefined]"
Object.prototype.toString.call(null); // "[object Null]"
// ... and more
@@toStringTag . @@toStringTag , , Iterator .
Promise , Constructor.prototype @@toStringTag . Math JSON . toString (: Intl.Locale), @@toStringTag Object.prototype.toString .
Object.prototype.toString.call(new Map()); // "[object Map]"
Object.prototype.toString.call(function* () {}); // "[object GeneratorFunction]"
Object.prototype.toString.call(Promise.resolve()); // "[object Promise]"
// ... and more
JavaScript "Object" .
class ValidatorClass {}
Object.prototype.toString.call(new ValidatorClass()); // "[object Object]"
toStringTag .
class ValidatorClass {
get [Symbol.toStringTag]() {
return "Validator";
}
}
Object.prototype.toString.call(new ValidatorClass()); // "[object Validator]"
2020 WebIDL DOM Symbol.toStringTag . , HTMLButtonElement Symbol.toStringTag .
const test = document.createElement("button");
test.toString(); // "[object HTMLButtonElement]"
test[Symbol.toStringTag]; // "HTMLButtonElement"
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-symbol.tostringtag |
This page was last modified on 2025 2 11 by MDN contributors.
SymbolObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |