News for hackers. Stuff that matters.
Re:The Strategy Pattern in JavaScript by tbranyen on Tuesday June 21, 2011 @05:10PM (#2680439)
Pretty much. I'm using this pattern in the following way:

SomeComponent.prototype.views = { home: { template: '/path/to/template', render: function(tmpl) { this.element.html(Mustache.to_html(tmpl, this.data)); } } };

I then have SomeComponent inherit the prototype of Component which has a generic render method. When I call the render method on any given component, it will have some logic to figure out which view it is in, then call the render method specific to that view with the correct template, that it fetches the content of under-the-hood.

Having consistent and expected behavior in your code is a huge win.

There are no comments on this comment yet.