tutorial

This is an old revision of the document!


Tutorial

To insert aspects, AspectScript needs an instrumentation phase. This instrumentation can be performed in two ways. The first is easier, but less efficient (useful for development). The second is a little bit more complicated, but more efficient (choose this one for production code).

The easy way - on-line transformation

This way is ideal when you are learning AspectScript or you are developing code, because the transformationis peformed each time your Javascript script is loaded. For on-line tranformation, it is only necessary to include the JavaScript script in the following way:

<script language="javascript" src="jst.php?url=script.js"> </script>

Where the jst.php is the PHP file available in the standard distribution of AspectScript.

The efficient way - off-line transformation

On-line transformatio is a little bit inefficient because the JavaScript script is transformed each time it is requested (on every page load). As an altenative, Javascript scripts can be transformed once and then include the transformed script. To attain this, you have to execute the following:

cat script.js | js -f 'launcher.js' > script-t.js

And then, in the web page you include the transformed script:

<script language="javascript" src="script-t.js"> </script>

The launcher.js script is included in the standard AspectScript distribution.

The aspects of AspectScript are just a pointcut-advice pair. Pointcuts and advices are plain JavaScript functions. For instance, if you need to identify all executions of the foo function.

var pointcut = AspectScript.Pointcuts.exec(foo);
var advice   = function() {
 alert("Foo was executed");
};
AspectScript.after(pointcut, advice);

If you want to learn more about AspectScript, you can see the examples page or read the technical report.

  • tutorial.1253894518.txt.gz
  • Last modified: 2009/10/19 18:08
  • (external edit)