prototype, each function object has an explicit prototype property, which represents the prototype of the object (function.prototype function object is an exception,There is no prototype attribute).
__proto__:Each object has an internal hidden property named __proto__,Point to its corresponding prototype object (named __proto__ in chrome and firefox, and can be accessed). The prototype chain was formed based on __proto__
(note:not based on the property prototype of the function object).
Simply put:__proto__ is an internal prototype,prototype is the constructor prototype (constructors are actually functions)
The prototype of a constructor is an object
So what is a constructor?
To create an object,First there is an object constructor,Just like in php,To create an object,First there must be a class
The essence of a constructor is a function,The following question is:how to create an object through this constructor?
Constructors construct objects.
First, __proto__ of all constructors/functions point to function.prototype, which is an empty function
number .__ proto__ === function.prototype
boolean .__ proto__ === function.prototype
string .__ proto__ === function.prototype
object .__ proto__ === function.prototype
function .__ proto__ === function.prototype
array .__ proto__ ===
regexp .__ proto__ === function.prototype
error .__ proto__ ===
date .__ proto__ ===
It shows that number and so on are all constructors,These constructors are actually an object of function. That is equivalent to var number=new function ();
math .__ proto__ === object.prototype
json .__ proto__ === object.prototype
"All constructors/functions" mentioned above of course include custom ones.as follows
function person ()
console.log (person .__ proto__ === function.prototype)
console.log (man .__ proto__ ===
What is this indicating?
All constructors come from function.prototype, even the root constructor object and the function itself. All constructors inherit the properties and methods of function.prototype.Such as length, call, apply, bind (es5).
function.prototype is also the only prototype whose typeof xxx.prototype is "function". The prototypes of the other constructors are all objects.as follows
console.log (typeof function.prototype)
console.log (typeof object.prototype)
console.log (typeof number.prototype)
console.log (typeof boolean.prototype)
console.log (typeof string.prototype)
console.log (typeof array.prototype)
console.log (typeof regexp.prototype)
console.log (typeof error.prototype)
console.log (typeof date.prototype)
console.log (typeof object.prototype)
Oh, it was mentioned above that it is an empty function,look at alert (function.prototype).
Knowing that __proto__ for all constructors (including built-in and custom) is function.prototype, who is __proto__ for function.prototype?
console.log (function.prototype .__ proto__ ===
This shows that all constructors are also ordinary js objects, and you can add/remove attributes to the constructor and so on.It also inherits all methods on object.prototype:tostring, valueof, hasownproperty, etc.
Who is __proto__ of object.prototype?
object.prototype .__ proto__ ===
Let me share a function, object, prototype, and __proto__ memory relationship diagram
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file