Besides Math.random , the built-in functions in JS are pure in design. You should not output a function with a new statement that will not do you the right job.
JavaScript is a multi-paradigm programming language that reveals the feelings of functional and oop . So you have pure functions without a prototype:
Math.round // whose typeof is function Math.floor // whose typeof is also function
Above, Math can be thought of as a namespace instead of an object type. Thus, this is just a container that provides you with a set of functions.
In contrast, if you reference prototype object functions in JavaScript, you will get undefined if you don't reference them through prototype:
Array.map // undefined Array.reduce // undefined
This is due to the fact that the Array is not intended for a namespace such as Math, it is an object class in the sense of OOP. Therefore, you need to call the function through your instance, for example
var list = new Array(3); list.map(function(a){ return 1 });
Otherwise, you can access the function through prototype to access a pure function where the this object is not bound. See the following instructions:
var list = [1,2,3]; typeof(Array.prototype.map);
The meaning of this is that JavaScript is designed to be written in OOP and Functional ways. You may need to play around with the function prototype, as I have given a few examples above, and this will explain you again :)
Tao pr
source share