The prototype property refers to the built-in Number prototype object.
The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT>
// Define a function that extends the capabilities of the Number object
function pythag(aValue1, aValue2)
{
return Math.sqrt((aValue1*aValue1) + (aValue2*aValue2));
}
// Register the new function
Number.prototype.pythag = pythag;
myNumber = new Number();
// Create a number object and test the Number.pythag() method
document.write(myNumber.pythag(3, 4))
document.write("<BR>")
</SCRIPT>
</BODY>
</HTML>ECMA 262 edition 2 - section - 15.2.3.1
ECMA 262 edition 2 - section - 15.7.4
ECMA 262 edition 3 - section - 15.7.3.1
| Prev | Home | Next |
| Number.POSITIVE_INFINITY | Up | Number.toExponential() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||