Constructor: The prototype property of each function points to an object that contains a unique non-enumerable property constructor, the value of which is such an object: constructor points to its constructor
Prototype: Each function contains a Prototype attribute, which points to a reference to an object, whereas an instance of each function (class) inherits properties from the object pointed to by the Prototype property. In other words, all objects created by the same function inherit an identical object.
function person (name) {this.name = name;}; Person.prototype.getName = function () {return this.name;}; var p = new Person ("Zhangsan"); Console.log (Person.prototype)
constructor function
function person (name) {
THIS.name = name;
}
Define the prototype of the person, and the properties in the prototype can be referenced by the custom object
Person.prototype = {
Getname:function () {
return this.name;
}
}
//Person.prototype.constructor=person Specifies constructor, the instantiated class points to person, and does not point to Object
var Zhang = new person ("Zhangsan");
Console.log (Person.prototype)
On the understanding of constructor and prototype