As in other high-level languages JavaScript also has the new operator, and we know that the new operator is used to instantiate a class to allocate an instance object in memory. But in JavaScript, all things are objects, why do we create objects through new? This article will bring you together to explore the mysteries of new in JavaScript ...
First, recognize the new operator:
function Animal(name){
this.name = name;
}
Animal.color = "black";
Animal.prototype.say = function(){
console.log("I‘m " + this.name);
};
var cat = new Animal("cat");
console.log(
cat.name, //cat
cat.height //undefined
);
cat.say(); //I‘m cat
console.log(
Animal.name, //Animal
Animal.color //back
);
Animal.say(); //Animal.say is not a function
Constructor prototype Object object instance (2018-09-09--Baidu map gives inspiration)
Source: https://www.cnblogs.com/AaronNotes/p/6529492.html
The new keyword in JavaScript is detailed