Tenderlove Making

パンツないな興奮 - Javascript stuff

While writing RKelly (a pure ruby javascript interpreter), I’ve run across weird cases in the ECMA spec that I didn’t know about before. For example, when coercing an object into a number, first the “valueOf” property is checked. That seemed to make sense to me. But then the spec says that if there is no “valueOf” property, to check the “toString” property and try to coerce that in to a number.

So, this bit of code: ~~~ javascript var x = new Object; x.valueOf = function() { return 11; }; x++; ~~~ is equivalent to this bit of code: ~~~ javascript var x = new Object; x.stringValue = function() { return “11”; } x++; ~~~ That is some underpants-free excitement.

« go back