The relationship between 1.__PROTO__ and prototype
The __proto__ of all objects point to the prototype of their constructors
var a = {"Test": ' Mico ', "Age": "};var" B = function () {};var c = new Date (); var d =/^[\d]$/;alert (a.__proto__ = object.pr Ototype); Truealert (b.__proto__ = = Function.prototype); Truealert (c.__proto__ = = Date.prototype); Truealert (d.__proto__ = = Regexp.prototype); True
Let's take a look at this piece of code
The printed t is like this, so what __proto__ is. Each object initializes a property inside it, that is, __proto__, when we access the property of an object, if the object does not exist inside this property, then he will go to __proto__ to find this attribute, this __proto__ will have their own __proto__, So we have been looking for, that is, what we usually call the concept of the prototype chain, when the object found in the constructor of this property has not yet, it will return to undefined.
The prototype chain inherits var Base = function () {}; Base.prototype.say = function () {alert ("saying");}; Base.prototype.getSaraly = function () {alert ("5000");}; Base.prototype.name = "Mico"; var Ctrl = function () {}; Ctrl.prototype = new Base (); Ctrl.prototype.name = ' perfunctory ah '; var a = new Ctrl (); Console.log (a); alert (a.name); Perfunctory Ah A.say (); Saying alert (a.__proto__ = = Ctrl.prototype);//true alert (a.__proto__.__proto__ = Base.prototype);//true
The print out of a is like this
As can be seen, when printing a.name, directly in the __proto__ inside find, found the direct return,
When printing a.saying, it was not found in __proto__. Will go down a layer __proto__ inside find, found the direct return, if find the constructor of __proto__ not found, return undefined.
Print
Alert (a.__proto__ = = Ctrl.prototype);//true
Alert (a.__proto__.__proto__ = = Base.prototype);//true
This is the addition of the prototype chain, __PROTO__ is a private property, and prototype is provided as an external interface, you can change the __proto__ property by prototype.
The relationship between __proto__ and prototype in JavaScript and the principle of prototype inheritance