New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object.prototype.toString() #671

Closed
timurtu opened this Issue Aug 17, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@timurtu

timurtu commented Aug 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 ^

@mathiasbynens

This comment has been minimized.

Show comment
Hide comment
@mathiasbynens

mathiasbynens Aug 17, 2016

Member

This would break backwards compatibility.

Member

mathiasbynens commented Aug 17, 2016

This would break backwards compatibility.

@timurtu

This comment has been minimized.

Show comment
Hide comment
@timurtu

timurtu commented Aug 17, 2016

How?

@mathiasbynens

This comment has been minimized.

Show comment
Hide comment
@mathiasbynens

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.

Member

mathiasbynens commented Aug 17, 2016

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.

@timurtu

This comment has been minimized.

Show comment
Hide comment
@timurtu

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?

@mathiasbynens

This comment has been minimized.

Show comment
Hide comment
@mathiasbynens

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.

Member

mathiasbynens commented Aug 17, 2016

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.

@domenic domenic closed this Aug 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment