When you create more than one instance of Apple, you will still only have only one instance of say()
in memory. However, when you create more than one instance of Banana, you will end up creating lots of instances of the say()
function.
That's why prototypes save memory. You also avoid the processing cost of creating and assigning the say()
function.
Also, if you change the parent object's properties, if the child does not replace that property, changes are visible from the child.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…