Math.constructor (Property)

A means of creating a new Math object.

Availability:

JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Property/method value type:Math object
JavaScript syntax:-Math.constructor

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.

Example code:

   <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>