AOP in JavaScript using Humax Framework


We, the programmers (architect/designer/developer) are used to engage with different programming lifestyle for developing applications. The journey started with sequential assembly programming. Before two decades, we were used procedural approach mainly in C format. Though SmallTalk introduced the object orientated approach, Bajurne Straustrop's C++ was created a biggest impact in programming using OO. Rest is history.

Along with these, two other programming approaches Functional Programming and Aspect Oriented Programming (AOP) are existing with us. JavaScript by default is a combination of mainly procedural, little bit functional and prototype based object oriented language. None of other modern languages (till now) do not have this capability.

To provide AOP support to JavaScript is not major a concern, because of the flexibility of JavaScript. Numerous frameworks available to apply aspect-orient approach in JavaScript. Humax is one of web framework provides AOP enabled JavaScript in version 0.2.

AOP - An Introduction

In a typical software application development, we design and develop the system with object in mind. In a healthcare application, for example, you might find objects of type Patient, Clinical Request, etc. Most of the modern technologies like Java, .NET are based on OO, because it is the more mature and well known programming approach. In addition to these, now a days we feel the necesscity of cross-cutting functionalities in our applications.

Cross-cutting Concerns

Assume that you are maintaining an enterprise insurance system. The system does not have instrumentation particularly logging. When the management requested to implement logging functionality into the system, in a typical OO way, you need to design and develop classes for logging and then instantiate and invoke necessary methods in each and every classes of the insurance system. This is called cross-cuttong concerns.

AOP is designed to handle cross-cutting concerns by Aspect for descriping these concerns and automatically incorporating them into the system.

Note that AOP is not a replacement of OOP, instead it works with OOP for resolving these issues.

Code Scattering

One of the issue we are facing in OOP or other programming methodologies is code maintainability when we have to make changes in a method signature. This would affect all the code consumed this method. Although, we can resolve this issue simply by versioning, AOP attempts to resolve this issue by allowing to express cross-cutting concerns in stand-alone modules called Aspects

Aspect and Its Concepts


Aspect is a programming module designed to capture a functionality that crosscuts an applications. An aspect can alter the behavior of the non-aspect part of an application. This can be achieved by advice at various join points specified in a quantification or query called a pointcut.

Join Points

A point in the target program where one or several aspects apply. The point can be a method, constructor, fields, exception and/or event of a class or collection of classes.


A pointcut is an entity which detects whether a given join point matches. Simply, a pointcut is either a quantification or query which specifies a set of joinpoints where an aspect applies. For example, we can apply an aspect in all methods starting with "get" in a class.


Advice is a mean of specifying code to run at a join point. The behavior in an advice are performed for all the join points that are included in the associated pointcut. Three types of advice exist:

  • before. The advice is executed before the execution of join point
  • after. The advice is executed after the execution of join point
  • around. The advice is executed around (part of advice code executed before join point and part of advice code executed after join point execution) the execution of join point.

Different AOP frameworks for different programming languages follow different model to adopt AOP. To know more about AOP concepts, start from Wikipedia: AOP page.

Programming with Metadata

Metadata programming is a way to add descriptive statement to annotate programming elements such as classes, properties and methods. These descriptive statement can be used used at runtime to affect application behaviour based on its value. In .NET, this can be achieved by Attributes (which is more mature and pioneer on using metadata programming) and in Java, by Annotation.

Humax allows you to use both AOP and metadata programming by Facet.

You might also like...



Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow