I want to add a new method to Number type, and then use it to change its own value. I write below code:
Number.prototype.maxx = function(N) {
if (N > this.valueOf()) {
//change this number value to N
}
}
var X = 5;
X.maxx(7);
console.log(X); //expect to show 7
I try something like below codes to change the value
this = N;
OR
this.valueOf(N);
OR
this.value = N; //of course number do not have any property named 'value'. but I just try it!
but none of them working.
Could you please give me some hint to do this. Thanks,
Math.max(X, N)or wrap this into your own class that allows overwrite of current value.