Javascript examples for Number:prototype
The prototype constructor can add new properties and methods to JavaScript numbers.
Number.prototype refers to the Number() object itself.
The following code shows how to Create a new number method that returns a number's half value:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> Number.prototype.myMethod = function() { return this.valueOf() / 2;/*from w ww . j a va2s .c o m*/ }; function myFunction() { var n = 55; document.getElementById("demo").innerHTML = n.myMethod(); } </script> </body> </html>