Three important facts

JS formula

Object.__proto__ === its constructor. Prototype

Root cause

Object.prototype is the (direct or indirect) prototype of all objects

Function of justice

All functions are constructed from functions

__proto__ === function.prototype

Any Function has Object/Array/Function

right

Doubt a

The prototype of the XXX

{name:'frank'The prototype of the}//Object.prototype
[1.2.3The prototype of the]//Array.prototype
ObjectThe prototype of the//Function.prototype
Copy the code

Interpretation of the

__proto__ : the prototype of Object is object. prototype: False

Where is wrong

The Chinese word “prototype” doesn’t distinguish between __proto__ and prototype, so we can only agree that a prototype defaults to __proto__, except that __proto__ is exactly the same as the function’s prototype

Doubt 2

contradiction

The prototype of [1,2,3] is array. prototype. You said object. prototype is the prototype of all objects

Where is wrong

There are two types of prototypes: direct and indirect. For ordinary objects, object. prototype is a direct prototype

Doubt three

Object.prototype is not the root Object

reason

Function is a prototype of all objects. Function is a prototype of all objects.

Where is wrong

This is the difference between an object. prototype Object and an object. prototype Object. Object is never going to contain another object in it. Now we need to sort out the building order of the JS world

The construction order of the JS world

  1. Create root object #101(toString), which has no name
  2. Create function prototype #208(Call /apply), prototype__proto__For # 101
  3. Create array prototype #404(push/pop), prototype__proto__For # 101
  4. Create Function #342, prototype__proto__For # 208 __
  5. Use function.prototype to store the prototype of the Function, equal to #208
  6. At this point, find the Function__proto__And prototype are both #208
  7. Create Object with Function
  8. Use object.prototype to store the prototype of the Object, equal to #101
  9. Create an Array with Function
  10. Array.prototype stores the Array prototype, equal to #404
  11. Create the Window object
  12. Name the functions in 7 and 9 using the window’s ‘Object’ ‘Array’ property
  13. Remember, when javascript creates an object, it does not give the object a name

  1. Create obj1 with new Object()

  2. New will set obj1’s __proto__ to object.prototype, which is #101

  3. Create arR1 with new Array()

  4. New will set arR1’s __proto__ to array. prototype, which is #404

  5. Create f1 with new Function

  6. New will set f1’s __proto__ to function.prototype, which is #208

  7. Define your own constructor, Person, to add an attribute to this

  8. Person automatically creates the Prototype property and the corresponding object #502

  9. Add a property to person. prototype #502

  10. Create object P with new Person()

  11. New will set p’s __proto__ to #502

What is the prototype of Object. Prototype?

What is the prototype of function.prototype?

Var f = () => {}, what is the prototype of f?

What is the prototype of Function?

What is the prototype of array.prototype. toString?

What is the prototype of Object?