Node.js Change Number Object Value Inside Prototype
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()) { //c
Solution 1:
Number.prototype.maxx = function(N) {
if (N > this.valueOf()) {
return N;
} else {
returnthis.valueOf();
}
}
var X = 5;
X = X.maxx(4);
One thing that I would like to highlight over here is when you call X.maxx you cannot change the value of this. Instead, you will have to re-assign the value being returned back from the method to X.
Post a Comment for "Node.js Change Number Object Value Inside Prototype"