Aspect-Oriented Programming

I’ve started looking at Aspect-Oriented Programming (AOP) recently, because of its potential for improving code readability and maintainability. This is mainly provided by the “separations of concerns” goal that AOP aims to achieve. To get started, I decided to jump in using the jQuery AOP plugin. Why jQuery/JavaScript instead of something more mature like AspectJ? Well, for one thing, I have spent quite a bit of personal time developing with JavaScript and it seemed like a logical place to get a good footing before diving deeper with something like AspectJ.


JavaScript Event Delegation

JavaScript Event Delegation is a technique you may have heard of. It’s a different way of using event handlers that offers clear benefits and is becoming more popular amongst web developers. I’ll give a brief overview of event delegation in JavaScript, along with why you should consider it. Note that this tutorial will use the great jQuery library (v. 1.3.1) for most examples.


Delegation is a fairly well-known design pattern. In short, it is a way for a method to produce its result simply by calling a method on another object, thus delegating responsibility to that object to provide the functionality needed by the method. For example, a Cashier object could store a delegate object called Calculator. Calling Cashier.addToTotal(value) would simply delegate to the contained object, calling Calculator.addToTotal(value).

How is delegation different than inheritance? With inheritance, the subclass inherits all of the functionality/behaviour of the parent class. You may not want or need this; in the preceding example, it would not make sense to have Cashier extend from Calculator simply because we wanted the addToTotal() behaviour/functionality. Delegation allows the behaviour advertised by a certain object/class to be provided by another.


Upgrade jQuery for better Opera support (Or just upgrade Opera)

I ran into a weird problem while testing one of my sites that used jQuery with Opera 9.26. (I happened to be using this older version of Opera because I am lazy to upgrade; I’m still using Firefox 2 despite the successful launch of FF3)

The issue was with an Ajax request I was sending. The return value was an array in JSON form. More specifically, the server was returning something like: Continued