11 comments

[ 0.32 ms ] story [ 46.4 ms ] thread
(comment deleted)
Nice and comprehensive article, cheers for the share.
Really insightful write-up but after reading through those code contortions it made me just want to stick with prototypal inheritance. If you have to go to those lengths to get your code to work, it seems like maybe you're doing it wrong, or using the wrong language...
Very my much impression. What you can abuse JS to do is impressive and I would never ever want to maintain a codebase that used these tricks.
These aren't "tricks" or "abuse". They're design patterns.
I had the opposite reaction. For me this is why I love JavaScript. It makes things I want to do in C++, C#, etc simple and easy.

Meta-programming is almost always scary looking regardless of language. But once written well using it is generally easy and I can ignore it and get back to work.

You can't avoid dealing with javascript when doing web development. Before you mention something like coffeescript, I have to say first that the mixin, forwarding and delegating code were only several lines long. Compare that to the amount of code used to compile to javascript.
Agreed. Generally I would argue against combining data and behaviour, for the very same reasons that the author wrote these abstractions.

However, I think there are better methods available. For example I would much prefer to organise related behaviour using Node modules (using Browserify if it’s a client app), which give you an extremely understandable way to group related behaviour AND hide private state.

Loved the post. Very nice & deliberate walk through of the various approaches.