First we must understand JS has several data types?
String number Boolean Object Null Undefined
Many other objects can be derived under Object objects
such as function Date Math array, etc.
I drew a picture of myself in a simple and rough way:
Red represents the object black represents the prototype object
Here are just a few points to keep in mind:
1, what are the objects that have prototype? function Array String Math object function etc some built-in objects
var student={
Name: ' Student ',
Grade: ' Class three ',
}
var b=new Object ();
Console.log (b.prototype);//undefined
var c= ' AAA ';
Console.log (c.prototype);//undefined
Console.log (String.prototype);//String common methods such as IndexOf
Why is it undefined because they're the objects that instantiate an object that is instantiated from an object is not a prototype object.
Therefore, you cannot use an instantiated object to. prototype
2,__proto__ is a property owned by each object, including an instantiated object, and the function is to find out which object the object derives from.
Console.log (c.prototype);//undefined
Console.log (c.__proto__);//string
Practice
Function Show () {
Alert (' Hello ');
}
Console.log (show.prototype);//object
Console.log (show.prototype.constructor);//function Show () {alert (' Hello ');}
Console.log (show.__proto__);//function () {}
Console.log (show.__proto__.__proto__);//object{}
Console.log (show.__proto__.__proto__.__proto__);//null
Array.prototype.show=function () {
Alert (' Hello ');
}
var arr=[1,2,3];
Arr.show ();//Instantiate an array also has a show method
JavaScript prototype prototype understanding