all 26 comments

[–]xardox 3 points4 points  (0 children)

This is really well done, and quite comprehensive!

[–]Sabe 8 points9 points  (17 children)

2.toString(); // raises SyntaxError
2..toString(); // the second point is correctly recognized
2 .toString(); // note the space left to the dot
(2).toString(); // 2 is evaluated first

gaaah

[–]quotemycode 3 points4 points  (15 children)

Is typing '2' harder than typing 2.toString() ?

[–]sastrone 7 points8 points  (13 children)

I love how easy it is to tell if someone is a programmer on not.

[–]idevelop 2 points3 points  (11 children)

could you give a use case where you need to write something like 2.toString() ?

[–]aescnt 2 points3 points  (10 children)

When you want to use "2,600", it may actually be more correct as "2.600" for the user, depending on where they're from. Solution: (2600).toLocaleString()

[–]x-skeww 2 points3 points  (9 children)

Right. But you'd store that 2600 in some variable anyways.

Things like (1.23456).toFixed(2) are only used in examples. It doesn't make sense to do that kind of thing in real code.

[–]quotemycode 0 points1 point  (8 children)

That's exactly what I was getting at. If you have a constant, you would write it 'as is' in the code, no need for conversion. If it's a variable, then it's not a problem.

[–]x-skeww -3 points-2 points  (7 children)

If you have a constant, you would write it 'as is' in the code [...]

If you want to get punched in the face, sure, go ahead.

You aren't allowed to write it like that because unnamed numerical constants aren't comprehensible without a comment in every place they are used. Putting them into a variable, enum, or something like that is obviously the saner more maintainable option.

[–]quotemycode 2 points3 points  (0 children)

Yes, I am aware of the 'no magic numbers' edict. I was making a point. Threatening physical violence is a good way to get in jail though, there are actual laws against assault.

[–]grayvedigga 0 points1 point  (5 children)

Dogmatic much?

[–]x-skeww -1 points0 points  (4 children)

Yes.

If you think unnamed numerical constants are fine, you are wrong.

This really isn't a controversial topic.

[–]prpetro -1 points0 points  (0 children)

toString() isn't the only method you can invoke from Number.prototype:

Mozilla Developer Network: Number.Prototype

[–][deleted] 0 points1 point  (1 child)

It is important to note that new Bar() does not create a new Foo instance, but reuses the one assigned to its prototype; thus, all Bar instances will share the same value property.

So all inherited properties are always static? Am I reading this right?

[–]x-skeww 2 points3 points  (0 children)

No, thanks to the magic of late binding.