Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upObject.prototype.toString() #671
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
This would break backwards compatibility. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timurtu
commented
Aug 17, 2016
|
How? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mathiasbynens
Aug 17, 2016
Member
Lots of existing code relies on Object.prototype.toString.call(someObject) returning '[object Object]'. It’s commonly used to detect whether a given value is an object.
P.S. If you’re using console.log anyway, why bother with toString at all? console.log(myObj) gives you what you want.
|
Lots of existing code relies on P.S. If you’re using |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timurtu
Aug 17, 2016
Okay I see your point but look how much more common this usage is. Doesn't it make more sense to return a string of the object with the toString method rather than a constant string saying what type of thing it is?
timurtu
commented
Aug 17, 2016
|
Okay I see your point but look how much more common this usage is. Doesn't it make more sense to return a string of the object with the toString method rather than a constant string saying what type of thing it is? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mathiasbynens
Aug 17, 2016
Member
It doesn’t matter if that makes more sense or not. We cannot break the web.
Anyway, this is not the place for such proposals. See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#proposals.
|
It doesn’t matter if that makes more sense or not. We cannot break the web. Anyway, this is not the place for such proposals. See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#proposals. |
timurtu commentedAug 17, 2016
The toString function on objects should return a JSON.stringify of the object.
const myObj = {a: 2}
console.log(myObj.toString()) // "[Object object]" // waste of time and energy ^
console.log(myObj.toString()) // "{ 'a': '2' }"
// useful information ^