This article describes how to obtain the prototype object of an object in Javascript. For more information about how to obtain the object's prototype object, see in Javascript. if we have an object but do not know its constructor, how to obtain its prototype object?
In Chrome or FireFox, we can directly use the _ proto _ attribute of an object to obtain its prototype object.
The code is as follows:
Function F (){};
Var foo = new F ();
Alert (foo. _ proto _ = F. prototype );
However, the __proto _ attribute is not supported in IE until IE11.
In browsers that do not support the _ proto _ attribute, how can we get the prototype object of the object? It can be obtained indirectly through constructor.
The code is as follows:
Function F (){};
Var foo = new F ();
Alert (foo. constructor. prototype = F. prototype );
The constructor attribute is not an object's own attribute, but obtained from the prototype object along the prototype chain. This attribute points to the constructor corresponding to the prototype object. The prototype attribute of the constructor points to the prototype object, so we can obtain it indirectly.
The above section describes how to get the prototype object in javascript. I hope you will like it.