javascript

Having come from a Ruby / Rails background, I was initially offput by Backbone.js' paradigm of models, views, and collections. Now that I've had a chance to build a few small projects with the versatile framework, I have a much better understanding of how to structure complicated relationships in Backbone. As the list of models in any project grows, you will almost certainly encounter a temptation to make a collection of collections. Consider a simple HTML5 audio player that can play or queue individual songs. We might represent it like this: var SongModel = Backbone.Model.extend({ defaults: { playCount: 0, }, play:…

While learning the pseudoclassical pattern in JavaScript at Hack Reactor, I discovered that there seems to be some confusion about the "best" way to achieve it. This is compounded by changing language standards over the years and the mounds of incorrect or outdated information out on the web. As you'll see, getting inheritance to work correctly is actually not as daunting as it seems. Let's explore this pattern by implementing some of the utensil family tree: Here we go. // This is our base Utensil class var Utensil = function() { // It has a few properties this.madeOf = "metal"; this.purpose = "eating"; this.…