JavaScript Number prototype Property

Date 对象参考手册JavaScript Number Object

Example

Create a method that adds a property to the number object and returns half of the number's value:

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

Create a Number object and call the myMet method:

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

xOutput:

27.5

Try it Yourself »

Definition and Usage

The prototype property allows you to add properties and methods to objects.

When constructing a property, all Number objects will be added with that property and its value.

When constructing a method, all Number objects will have this method.

Note:Number.prototype does not allow referencing a single Number object, but the Number() object can be used.

Note:The prototype is a constructor for global objects and can be used for all JavaScript objects.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the prototype property.


Syntax

object.prototype.name=value


Date 对象参考手册JavaScript Number Object

Other Extensions