When we create an object with a constructor, its properties are added to this. And the properties that are added to this will not actually change with the entity, at this point, this approach is inefficient. For example:
function She () { this. Name = ' Anna ';}
This means that every time we create an instance object with new her, we generate a completely new Name property, and we have the storage space in memory that belongs to that property. In fact, we can add the name attribute to the prototype so that all instances can share the Name property:
function= ' Anna ';
In this way, when we create the object with new her (), the Name property is no longer a private property of the new object, but is added to the prototype of the object. While this can be efficient, it's also for immutable properties in the instance object, which is certain, otherwise change this property, all the new objects created by this property will be changed, this is not what we want AH ~ ~ ~. The public properties of an object are particularly appropriate for this method.
Let's refine the previous example:
function= ' Anna 'function() { returnthis. Name;} function new== ' women ';
As you can see, we usually build the inheritance work before we do the prototype object extension, otherwise the subsequent new attribute methods in His.prototype might erase the inherited stuff.
function Child (f, m) { this. Eat = f; this. Don =new== ' Jok 'function() { returnthis. Don}
As you can see, the difference between actually calling ToString () is only a small number of operations behind the scenes. The main difference is the attribute, and the method's lookup will occur more in Her.prototype.
Good sleepy, a day is very depressed, do not knock, early to sleep, and then back. ( ̄┰ ̄*)
JavaScript---Migrating shared properties to prototypes