HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Number prototype Property

Date Object Reference JavaScript Number Object

Example

Create a method that gives the number object a property that returns the number's half value:

Number.prototype.myMet=function()
{
this.myProp=this.valueOf()/2;
}

Make a Number object, then call the myMet method:

var n = new Number(55);
n.myMet();
var x = n.myProp;

The result of x will be:


Try it yourself »

Definition and Usage

The prototype constructor allows you to add new properties and methods to the Number() object.

When constructing a property, ALL number objects will be given the property, and its value, as default.

When constructing a method, ALL number objects will have this method available.

Note: Number.prototype does not refer to a single number object, but to the Number() object itself.

Note: Prototype is a global object constructor which is available for all JavaScript objects.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The prototype property is supported in all major browsers.


Syntax

object.prototype.name=value


Date Object Reference JavaScript Number Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE