- [Presenter] The effects of prototype chains
on app memory and code organization
are compelling in themselves,
and there's a bonus effect
that makes using prototypes even sweeter.
You've seen how chained prototypes
share a single set of keys and values,
and due to this relationship,
a change to a parent prototype
changes the code of all constructors
that inherit from it, without needing
to make changes to the code of those prototypes.
This works much the same way as using
a single CSS style sheet for all the pages in a website,
which allows you to change the style site-wide
with an edit to just that single CSS document.
So, in our code for Hansel and Petal,
the item prototype down here on line 646
contains the type property,
and it also contains the log item method.
And both of these are inherited
by all of our other constructors.
Well, imagine that the store decided to end the distinction
between floral and other goods,
and instead to classify all sales
as either goods or services,
if each constructor still had its own prototype
with no chaining,
we'd have to make this change to the type value
in each constructor.
But because we've connected our prototypes
into a prototype chain,
we only have to make that change once.
So here below the item constructor,
I can change the item dot prototype dot type value
from floral to goods.
And then I'm going to save that change.
And I already have this page running from HTTP server.
So switching over to the browser and reloading,
I'll go to the arrangements page,
add one of those to the cart.
And I can see in the console that now the type property
for this item is goods,
and then going to live plants,
I'll add one of those and same thing type of goods,
build a bouquet.
I'll just add one stem,
add that to the cart and the type is goods.
So the inheritance created by our prototype chain
makes our code not only more concise,
but easier to maintain as well.