Re: Value types versus .valueOf

2014-06-10 Thread Brendan Eich
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

Value types versus .valueOf

2014-06-09 Thread Alex Vincent
I like the idea of value types, but I wonder if, for terminating decimal numbers, the .valueOf() method from Object.prototype might be sufficient for many operations. Example: function SmallDecimal(k) { this.__value__ = k; } SmallDecimal.prototype.valueOf = function() { return