Javascript and prototype of __proto__

 

__proto __ (implicit prototype) and the prototype (prototype explicit)

  What is?

  • Explicit prototype explicit prototype property:

Each function after you create will have a property named prototype, this property points to the prototype object function.

  • Implicit prototype implicit prototype link:
Any JavaScript object has a built-in attribute [[the prototype]], there is no standard way to access ES5 before the built-in properties,
However, most browsers support access by __proto__. With the built-in ES5 attribute criteria for the Get method of Object.getPrototypeOf ().
  Object.prototype This object is an exception, its value is null __proto__
  • Relations between the two:

Implicit prototype point to create the object constructor (constructor) of the prototype

  effect?

  • Explicit action prototype: Prototype for sharing on inheritance and attribute.
  • Implicit action prototype: Prototype chain configuration, for achieving the same prototype-based inheritance. For example, when we visited the x property of the object obj,

   If you can not find in obj, then it will in turn look down __proto__.


 

Example:

A constructor declaration, a prototype of the object A and a method of adding an attribute,

A function to create an object with a:

1 A.prototype.name = "Jack";
2 A.prototype.say = function () {
3     console.log("hello");
4 }
6 function A() {
7     8 }
9 var a = new A( );

Let's look at the output wave of the console. . .

 First, the object of a __proto __ (implicit prototype) point A the prototype (prototype object)

 And a .__ proto __.__ proto__ and equivalent to the following long list of things that, in fact, is equivalent to the prototype object --Object.prototype ancestor of all objects

 In the definition of the prototype chain, i.e. Object.prototype prototype chain end, there is no upward.

 

 

 A prototype of the constructor, which is a target of the place pointed __proto__

 

* __Proto__ A constructor of what they point to?

 

 

    Implicit prototype point constructor of the object constructor function prototype (A .__ proto__ === A.constructor.prototype).

Because the function is a special object , " Function.prototype"that is, all function prototypes, is usually considered a Function function can be manufactured by the new.

换句话说,Function.prototype上面承载了用于继承给所有函数的那些属性,例如:call、bind、apply等。


 

部分内容参考自:https://www.zhihu.com/question/34183746/answer/59043879

 

Guess you like

Origin www.cnblogs.com/abcdecsf/p/12432263.html