| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | [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 2015 ..
toString() , .
function Dog(name) {
this.name = name;
}
const dog1 = new Dog("Gabby");
Dog.prototype.toString = function dogToString() {
return `${this.name}`;
};
console.log(dog1.toString());
// Expected output: "Gabby"
obj.toString()
, .
toString(), , , . , toString() , Object. , toString() "[object ]", . :
var o = new Object();
o.toString(); // [object Object]
:
JavaScript 1.8.5, toString(), null, [object Null], undefined, [object Undefined], 5- ECMAScript . toString() .
toString , toString() . toString() . toString() , , , .
Dog theDog, Dog:
function Dog(name, breed, color, sex) {
this.name = name;
this.breed = breed;
this.color = color;
this.sex = sex;
}
theDog = new Dog("", "", "", "");
toString() , , Object:
theDog.toString(); // [object Object]
dogToString(), toString() . , , , , " = ;".
Dog.prototype.toString = function dogToString() {
var ret =
" " +
this.name +
" - " +
this.sex +
", " +
this.color +
" " +
this.breed;
return ret;
};
Dog.prototype.toString = function dogToString() {
return `Dog ${this.name} is a ${this.sex} ${this.color} ${this.breed}`;
};
, theDog , JavaScript dogToString(), :
- ,
toString toString() . Object.prototype.toString() , Function.prototype.call() Function.prototype.apply(), , , thisArg.
var toString = Object.prototype.toString;
toString.call(new Date()); // [object Date]
toString.call(new String()); // [object String]
toString.call(Math); // [object Math]
// JavaScript 1.8.5
toString.call(undefined); // [object Undefined]
toString.call(null); // [object Null]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-object.prototype.tostring |
Object.prototype.toString Symbol.toStringTag core-jsObject.prototype.valueOf()Number.prototype.toString()Symbol.toPrimitiveSymbol.toStringTagThis page was last modified on 29 . 2026 . by MDN contributors.
ObjectObject.assign()Object.create()Object.defineProperties()Object.defineProperty()Object.entries()Object.freeze()Object.fromEntries()Object.getOwnPropertyDescriptor()Object.getOwnPropertyDescriptors()Object.getOwnPropertyNames()Object.getOwnPropertySymbols()Object.getPrototypeOf()groupBy()hasOwn()Object.is()Object.isExtensible()Object.isFrozen()Object.isSealed()Object.keys()Object.preventExtensions()Object.seal()Object.setPrototypeOf()Object.values()Object.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()Object/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 |