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 this.__value__.toString(10);
}

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

/*
true,false,false,true,false,true
*/

I still want to see value types go forward:  in the above example, x + y
would result in "23", where x - y === -1.  Perhaps .valueOf could be used
in testing simple value types implementations.
-- 
"The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own."
-- Alexander J. Vincent, June 30, 2001
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to