Class: Aspects

helma.Aspects()

new Aspects()

Library for adding Aspects

Provides static methods to wrap existing functions inside a javascript closure in order to add additional behavior without overriding the existing one.

Based on code by roman porotnikov, http://www.jroller.com/page/deep/20030701

Note: Each prototype that uses aspects must implement a method onCodeUpdate() to prevent aspects being lost when the prototype is re-compiled
Source:

Methods

addAfter(obj, fname, after)

Adds a function to be called after an existing function.

The return value of the original function is passed to the added function as its first argument. In addition, the added function also receives an array of the original arguments, the original function and the scope object of the original function as additional parameters.
Parameters:
Name Type Description
obj Object as Object, the object of which the original function is a property
fname String as String, the property name of the original function
after function as Function, the function to be called after the original function
Source:
Returns:
Function A new function, wrapping the original function

addAround(obj, fname, around)

Wraps an additional function around the original function.

The added function receives as its arguments an array of the original arguments, the original function and the scope object of the original function. The original function is not called directly and needs to be invoked by the added function.
Parameters:
Name Type Description
obj Object as Object, the object of which the original function is a property
fname String as String, the property name of the original function
around function as Function, the function to be called inside the original function
Source:
Returns:
Function A new function, wrapping the original function

addBefore(obj, fname, before)

Adds a function to be called before the orginal function.

The return value of the added function needs to provide the array of arguments that is passed to the original function. The added function receives an array of the original arguments, the original function and the scope object of the original function as its parameters.
Parameters:
Name Type Description
obj Object The object of which the original function is a property
fname String The property name of the original function
before function The function to be called before the original function
Source:
Returns:
Function A new function, wrapping the original function