Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Number prototype property

JavaScript Number prototype property

Date Object Reference JavaScript Number object

Example

Create a method that gives a Number object a property returning half its 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

;

x Output result:

27.5

Try it »


Definition and Usage

The prototype property allows you to add properties and methods to an object.

When a property is constructed, all Number objects get this property and value added.

When a method is constructed, all Number objects get this method.

Note: Number.prototype cannot reference a single Number object, but the Number() object can be used.

**Note:** prototype is a global constructor property available to all JavaScript objects.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the prototype property.


Syntax

object.prototype.

name

=

value


Date Object Reference JavaScript Number object