extend - Extending Math object in JavaScript -


Since it is a poor practice to increase the built-in objects, I think of creating a local object It had been spread globally, e.g. With $ Expansion (obj, math) . Mathematics is an object, although you can not access it for any of your property such as:

  {console.log (obj)) . ; }   

Why?

Because they're all defining non countable . Almost all the underlying properties of defined objects defined are non-calculable when you calculate the properties in the object (via for-in or Object.keys ) Non-numerical properties do not appear.

Two ideas for you, though:

  1. You can make your object form your prototype with math Such as:

     with  // meth compose the mimeth object as your prototype MyMath = Object.create (Math); // Check that Mameth has a math function on display (MyMath.floor (2.3)); // utility function function display (msg) {document.body.insertAdjacentHTML ("first", ""); ES5 introduced a new function, which can get names of all properties (both calculable and non-calculable).    Prototype of an object (and because of  math   Object.prototype , you probably want "own" property. ) You can do this on an ES5-compliant engine: 
      // Create a MyMath object with all properties on Mather Mymath = {}; Object.getOwnPropertyNames (Math). ForEach (function (name) {Maimuth [name] = Math [name];}); // Check that Mameth has a math function on display (MyMath.floor (2.3)); // utility function function display (msg) {document.body.insertAdjacentHTML ("first", ""); Option 1 is probably your better option, not least because  single-argument version of the object. Make pre-ES 5 engines can be shimmed / polyfilled.   

    Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -