Value types versus .valueOf

Brendan Eich brendan at mozilla.org
Tue Jun 10 20:10:02 PDT 2014


Alex Vincent wrote:
> var x = new SmallDecimal(2);
> var y = new SmallDecimal(3);
> [x < y, x > y, x == y, x <= y, x >= y, x != y]

valueOf doesn't work for SmallDecimal(2) == SmallDecimal(2), though. You 
have to hash-cons, which kils performance.

String relational order is wrong for numeric types, to boot:

js> '10' < '2'
true

So valueOf is a no-go.

/be


More information about the es-discuss mailing list