How would I instead be able to have those two methods return let's say 2 times the value of the numberCode:Number.prototype.valueOf = function() {return 1}; Number.prototype.toString = Number.prototype.valueOf; var x = new Number(7); alert(x); //Alerts 1
Note: While I want to know how to do something like this in general for predefined objects, I know that the current example is not very practical.Code:Number.prototype.valueOf = function() {return /* Magic Code...something like (this*2) */}; Number.prototype.toString = Number.prototype.valueOf; var x = new Number(7); alert(x); //Should alert 14



Reply With Quote


Bookmarks