Reputation: 25270
Can someone explain me how to overcome this thing?
String.prototype.one = 1;
"one".one; //returns 1
Number.prototype.one = 1;
1.one; //returns 'SyntaxError: Unexpected token ILLEGAL'
Upvotes: 2
Views: 69
Reputation: 48771
This is because the interpreter sees a .
after a number as a decimal, not a property accessor, so it sees it as this:
(1.)one // SyntaxError
Give it another .
, and it'll work.
1..one
It now sees it as this:
(1.).one
Other solutions:
1.0.one
1["one"]
(1).one
Upvotes: 9