Constructor Summary Essay

Objects include properties and methods

[properties are the information that needs to be remembered, and methods are the services that objects can provide] The

constructor is an ordinary function, but the this variable is used internally. By using the new operator on the constructor, an instance is created, and the this variable is bound to the instance object.

Generated only once in memory, and then all instances point to that memory address. Every constructor has a prototype property that points to another object. All properties and methods of this object will be inherited by the instance of the constructor.

Cat.prototype.price = function(){
    alert("5 yuan")
};

Note [add () after calling the method]==>cat1.price(); // 5 yuan

Cat.prototype.type = " animal";
alert(cat1.type); // animal

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326951201&siteId=291194637