A prototype object

Basic types: String, number, Boolean, object, null, undefined

Reference types: String, Number, Boolean, Object, Function, Array, Date, RegExp, Error

Every javascript object (except null) is created with a __proto__ attribute, which points to the prototypeobject (A.__proto__ == string.prototype). Each prototype has a constructor attribute, Associated prototype object (a.c onstrucor = = String. The prototype. The constructor)

var a = new String('abc')
// The prototype of a is String
a.__proto__==String.prototype
// Both a and String refer to the String prototype
a.constructor==String.prototype.constructor
/ /. Construcor pointed to a String
var a = new Number(Awesome!)
var a = new Object(a)Copy the code

The procedure for creating an object in JavaScript:

function Mother(lastName){
    this.lastName = lastName
}
var son = new Mother("Da")

1.Create a new object son2.[[prototype]] link son.__proto__= mother.prototype3.New objects and function callsthisMother. Call (son,"Da")
4.Execute the code in the constructor son.lastname5.If the function returns no value, the new object is automatically returnedreturn this
Copy the code

Prototype chain

Each constructor has a prototype object, which contains a pointer to the constructor, and each instance contains an internal pointer to the prototype object. So what if we made the prototype object equal to an instance of another type? Obviously, the stereotype object will contain a pointer to another stereotype, which in turn will contain a pointer to another constructor. If the other prototype is an instance of another type, the relationship still holds. In this way, a chain of examples and prototypes is formed. This is the basic concept of the so-called prototype chain.