What is a prototype object?
In JS, each created function has a prototype attribute, which points to an object, which is the prototype object
function
Results from the Chrome browser:
What are prototype objects capable of?
First, when you call a function with new, an object instance is created and returned to this object
You can see that a is an object named Lla , with a __prototype__ attribute (described later), which can be thought of as empty; why is it empty? Because the inside of the constructor is empty;
How can we make it not empty?
OK, Christina 18 of the handsome pot thick line up. Cough.
The This in the constructor is pointed to B in the new call, so B has two attributes, age,name;
Back to the question, what's the use of prototype objects?
B is an instantiated object, and through the code above we find that B has not changed, but it can access the prototype object
The method, so. The role of the prototype object comes out, you can add a variety of shared properties for your instantiated objects and
method, these properties and methods are shared by all instances.
JS Prototype Object