News for hackers. Stuff that matters.
Re:The Strategy Pattern in JavaScript by jbwyme on Tuesday June 21, 2011 @05:03PM (#2680408)
Tell me if I have this straight: this pattern basically says to create a generic object with properties and handlers to allow for simple iteration, creation, etc. like you would with an interface. Then, if needed, use a prototype to set defaults?
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.