I've been doing some work lately with the Isogenic Engine framework and it's exposed me to the concept of classes in JavaScript. Now, classes are nothing new to programming, but I've never really been formally introduced to them so it was a big eye-opener for me to learn about how they work.
What I found out was that I had actually been using classes for a while since Backbone is built on the concept. But actually understanding the application of the concept was a great help in advancing my understanding.
The short version (as I interpret it) is that with classes, a developer can write well-defined and scoped code and then make that well-written code available elsewhere in the application without re-writing it. As with most concepts in coding, actual code is often more helpful than textual descriptions, so I'd recommend looking at a blog article that John Resig wrote about this very topic and even shared a smallish bit of code to make it easy to use classes.
I thought this was pretty awesome and I immediately set about putting it to use in some code that I was working on at the time. At the moment, the most useful class that I've written is one that allows for simply inheriting the EventEmitter in NodeJS.
Using the 'class.extend' module, which is a copy/paste of Resig's code, I created this batch of code that I use as the parent for most of my other classes so that the resulting objects can emit and consume events.
What I found out was that I had actually been using classes for a while since Backbone is built on the concept. But actually understanding the application of the concept was a great help in advancing my understanding.
The short version (as I interpret it) is that with classes, a developer can write well-defined and scoped code and then make that well-written code available elsewhere in the application without re-writing it. As with most concepts in coding, actual code is often more helpful than textual descriptions, so I'd recommend looking at a blog article that John Resig wrote about this very topic and even shared a smallish bit of code to make it easy to use classes.
I thought this was pretty awesome and I immediately set about putting it to use in some code that I was working on at the time. At the moment, the most useful class that I've written is one that allows for simply inheriting the EventEmitter in NodeJS.
Using the 'class.extend' module, which is a copy/paste of Resig's code, I created this batch of code that I use as the parent for most of my other classes so that the resulting objects can emit and consume events.
With this pattern, I can write very focused classes and tie them together with something of an event bus where data is passed back and forth in an evented manner. Nesting callbacks is gone, but tracking event chains is in.