JavaScript The Better Parts — what everyone missed

adrian smith
2 min readDec 14, 2014

--

Earlier this year I saw a video on Youtube by Douglas Crockford, for the uninitiated he is author of JavaScript the best parts and he popularised JSON, it is a fantastic talk that I encourage you to watch here:

As a Web Developer myself I took the time to watch all of it but I am not sure enough people took note, perhaps hidden inside was the most pertinent section of code I have come across in my working career thus far:

In his video he said he was writing objects like this now, at the time I was struggling with the prototype chain and how inheritance and objects work in JavaScript coming from a class based language so I thought I’d give this approach a go, seems simple enough.

The approach uses parasitic inheritance, enclosed scope with easy to understand public and private methods.

If you are interested in seeing the approach in a code base I have a terribly made game I am working on here:

https://github.com/slifin/Flourish-babylon/blob/gh-pages/js/planet.js

Full of globals and other misdeeds but it does however display the approach as shown in the image above.

I personally have found it easy to remember, readable, easy to inherit, and makes working in JavaScript for me a pleasure I hope it also does the same for you.

--

--