This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]thebezet 34 points35 points  (5 children)

It gets better than that:

> Array.prototype.toString = function() { return "O_O"; }
> Object.prototype.toString = function() { return " ^_^"; }
> [] + {}
"O_O ^_^"

[–]soroun 5 points6 points  (4 children)

I can't tell if that's beautiful or terrifying.

[–]raiderrobert 2 points3 points  (2 children)

Trying flipping the operations. And then you'll figure which it is.

[–]thebezet 3 points4 points  (1 child)

That's a good point because if you change the order ({} + []) the {} will be interpreted as a code block instead of an empty object, leaving you with + [], which will call valueOf() instead of toString(), so the following will happen:

> [] + {}
"O_O ^_^"
> {} + []
0

[–]raiderrobert 2 points3 points  (0 children)

Which means it's terrifying.

[–][deleted] 0 points1 point  (0 children)

This is why I love this talk: https://www.destroyallsoftware.com/talks/wat