I bring you prototypes and deeper understanding

JavaScript includes a prototype linkage feature that allows one object to
inherit the properties of another. When used well, this can reduce object
initialization time and memory consumption.

Unfortunately, he doesn’t give a concrete example of that reduction. Prototype
inkage is explained fairly well in Chapter 5, but the concept of a prototype
linkage that’s “used well” didn’t click for me until I spent some time looking
at how Prolix evolved.

Telling a story with numbers

Here’s a numerical recap. The prototypical trie code I started with was 1,045
bytes and it took 0.285 seconds to execute. The functional code I ended with was
677 bytes and took 0.448 seconds to execute. So the prototypical version wins on
speed and the functional version wins on size.

The best of both worlds is code that’s small and fast. We can get there if we
take advantage of JavaScript’s prototype linkage.

The code above is 813 bytes, and it executes in 0.289 seconds. That makes it
1.29 times smaller than the original and only 1.01 times slower. The almost
1.55x speed improvement over the functional version makes the extra 136 bytes
worth it, since that translates into visible seconds when you run Prolix
on a phone.

I bring you deeper understanding

The nugget of insight here is that a functional construction pattern in
JavaScript has to create new functions for an object every time it’s called.
Prototypical inheritance lets functions be reused, which can really speed things
up if you’re creating a lot of objects.

However, I’m still not a big fan of the excessive this verbiage that
prototypical inheritance brings. For now, I’ll stick with a functional style
unless (as is the case here) other methods offer measurable advantages.