Number.prototype

JavaScript 1.1+, JScript 1.0+ Nav3+, NES2+, IE 3+, Opera3+ Syntax

Number. prototype.property

Number. prototype.method
						

Description

The prototype property of the Number object allows you to add properties or methods to all instances of this class.

Example

Listing 6.187 shows how the prototype property is used.

Listing 6.187 Example of prototype
 <html> <body> <script language="JavaScript"> <!–– Hide // Creates a new Number property myProp var myProp = new Number(); // sample function multiplies number by 3 function triple(num){ var result; result = (num * 3); return result; } // Add the prototype peoperty to the number object Number.prototype.calc3 = triple; document.write("Example demonstrates the prototype property ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.