1. Three most important pieces of knowledge:
1. JS formula
Object.__proto__=== its constructor. Prototype
(JS unique formula, if not set formula)
2. The root cause
Object.prototype
Is the (direct or indirect) archetype of all objects.
3. Function axioms
- All functions are defined by
Funcition
Structure of the Any function __proto__=== funcition.prototyp
- Any function has Object/Array/Funciton
Second, JS world
The order in which the JS world is constructed
1. Create root object #101
- There are some properties in there, like
toString
.valueOf
- The root object has no name
- The prototype is defined as
null
, i.e.,__proto__ : null
2. The root object has no name to create the prototype of the function #208
- There are some properties in there, like
call
,apply
- I’m created from a root object, so I’m modeled after a root object
# 101
, i.e.,__proto__ : #101
3. Create an array prototype #404
- There are some properties in there, like
push
,pop
- I’m created from a root object, so I’m modeled after a root object
# 101
, i.e.,__proto__ : #101
Create Function #342 and prototype __p = #208
- with
Function.prototype
The prototype of the storage function is equal to# 208
- Found at this time
Function
的__proto__
和prototype
Are all# 208
5. Use Function to create Object
- with
Object.prototype
The prototype of the stored object is equal to# 101
6. Create an Array with Function
- with
Array.prototype
The prototype of the storage array is equal to# 404
7. Create the window object
- with
window
的'Object'
'Array'
Property names the functions in 5 and 6 - Remember that when JS creates an object, it does not give the object a name
The construction order of the JS world (Continuation 1)
- with
new Object()
createobj1
new
willobj1
The prototype of the__p
Set toObject.prototype
, that is,# 101
- with
new Array(
) to create aarr1
new
willarr1
The prototype of the__p
Set toArray.prototype
, that is,# 404
- with
new Function
createf1
new
willf
1 the prototype of the__p
Set toFunction.prototyp
E, that’s just e# 208
The construction order of the JS world (Continuation 2)
- Define your own constructors
Person
The function givesthis
Add attribute Perso
N Automatic Creationprototype
Property and corresponding object# 502
- in
Person.prototype #502
Add attributes to it - with
new Person()
Create an objectp
new
willp
The prototype of the__p
Set to# 502