Both Netscape and MSIE support a constructor property for the Math object. It is unlikely you would ever want to construct a copy of the Math object.
However, this is useful not for the purpose of cloning the Math object but so that you can extend it by adding your own properties and methods to its prototype.
This technique is demonstrated in the example which appears to add a pythag() function to the Math object although it is really added to the Object() object prototype.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> // Define a function that extends the capabilities of the Math object function pythag(aValue1, aValue2) { return Math.sqrt((aValue1*aValue1) + (aValue2*aValue2)); } // Register the new function Math.constructor.prototype.pythag = pythag; // Test the Math.pythag() method document.write(Math.pythag(3, 4)) document.write("<BR>") </SCRIPT> </BODY> </HTML>
Prev | Home | Next |
Math.ceil() | Up | Math.cos() |
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. |