Javascript - Number prototype Property

The prototype constructor can add new properties and methods to JavaScript Number class.

Description

The prototype constructor can add new properties and methods to JavaScript Number class.

Syntax

Number.prototype.name = value

Example

The following code shows how to create a new number method that returns a number's half value:

Demo

Number.prototype.myMethod = function() {
    return this.valueOf() / 2;
};

var n = 55;//from   w  w  w .ja v a2  s. c  o m
console.log(n.myMethod());

Result