Methods of the helma.Aspects module.
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Aspects.js')
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Aspects.js')
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
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
methods
- addBefore(obj, fname, before)
- addAfter(obj, fname, after)
- addAround(obj, fname, around)
Methods
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.
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
Object | obj | The object of which the original function is a property |
String | fname | The property name of the original function |
Function | before | The function to be called before the original function |
returns
Function A new function, wrapping the original function |
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.
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
Object | obj | as Object, the object of which the original function is a property |
String | fname | as String, the property name of the original function |
Function | after | as Function, the function to be called after the original function |
returns
Function A new function, wrapping the original function |
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.
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
Object | obj | as Object, the object of which the original function is a property |
String | fname | as String, the property name of the original function |
Function | around | as Function, the function to be called inside the original function |
returns
Function A new function, wrapping the original function |