Hacker News new | past | comments | ask | show | jobs | submit login
Mixins, Forwarding, and Delegation in JavaScript (raganwald.com)
108 points by johanbrook on April 10, 2014 | hide | past | favorite | 11 comments



Particularly if you use coffeescript, mixen can be a more capable option: http://github.hubspot.com/mixen/


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...


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.


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.


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.


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.


Big improvement over the last one [1]. I learned some things. Looking forward to seeing the next one.

[1] https://news.ycombinator.com/item?id=7496968


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


Nice and comprehensive article, cheers for the share.


angularjs please




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: