4 ms·
Mixins, Forwarding, and Delegation in JavaScript
- deleted 12y ago[deleted]
- sfeng 12y agoParticularly if you use coffeescript, mixen can be a more capable option: http://github.hubspot.com/mixen/ http://github.hubspot.com/mixen/
- mxxx 12y agoNice and comprehensive article, cheers for the share.
- drderidder 12y agoReally 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...
- peterashford 12y agoVery 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.
- ephemeralgomi 12y agoThese aren't "tricks" or "abuse". They're design patterns.
- greggman 12y agoI 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.
- ilcosrn 12y agoYou 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.
- blakehaswell 12y agoAgreed. 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.
- jdlshore 12y agoBig 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 https://news.ycombinator.com/item?id=7496968
- enowbi 12y agoangularjs please
- ifandelse 12y agoLoved the post. Very nice & deliberate walk through of the various approaches.