tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial [2009/09/07 21:11]
aspectscript
tutorial [2009/10/26 17:55] (current)
aspectscript
Line 1: Line 1:
 ====== Tutorial ====== ====== Tutorial ======
  
-Here, you can find a small tutorial of AspectScript. For more information, please read its [[technical report|technical report]].  +===== Getting Started =====
  
-===== Getting Start =====+In order to be able to dynamically weave aspects without modifying a particular JavaScript engine, AspectScript first performs a code transformation phase in which some expressions are rewritten. 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 option is ideal when you are learning AspectScript or you are developing code, because the code is transformed each time your Javascript script is loaded. For on-line tranformation, it is only necessary to include the JavaScript source in the following way:
  
-The code transformation can use in two ways. The first is easier, but it is lesser efficient. The second is a little bit more complicated but it is more efficient.   
-=== The easy way === 
-This way is ideal when you are learning AspectScript or you are editing and testing the JavaScript code. To use AspectScript, you has to include a JavaScript script in the following way: 
-you must change that by: 
 <code html> <code html>
 <script language="javascript" src="jst.php?url=script.js"> </script> <script language="javascript" src="jst.php?url=script.js"> </script>
 </code> </code>
-The **jst.php** is the PHP file available in AspectScript + 
-=== The efficient way === +Where the **jst.php** is the PHP file available in the standard distribution of AspectScript
-The inefficient of previous solution is the problem because AspectScript modifies the JavaScript code every time that the Web page is loadedYou can transform the JavaScript code once and latter you include the new script. To transform the code, you must execute the code:+ 
 +For instance, [[http://www.pleiad.cl/aspectscript/external/tetris/tetris.js|this]] is the original tetris application, and the [[http://www.pleiad.cl/aspectscript/external/aspectscript/jst.php?url=http://www.pleiad.cl/aspectscript/external/tetris/tetris.js|transformed one]] using jst.php (it can take some time to load because the transformation is a heavy process, please click once). 
 + 
 +=== The efficient way - off-line transformation === 
 + 
 +On-line transformation is a little bit inefficient because the scripts are transformed each time they are requested (on every page load)As an altenative, Javascript scripts can be transformed once and then the transformed code included in pages.  The following commands performs this off-line transformation: 
 <code Bash> <code Bash>
-cat script.js | js -f 'launcher.js'newscript.js+cat script.js | js -f 'launcher.js'script-t.js
 </code> </code>
-In the web page you include the new script+ 
 +And then, in the web page you include the transformed script
 <code html> <code html>
-<script language="javascript" src="newscript.js"> </script>+<script language="javascript" src="script-t.js"> </script>
 </code> </code>
  
-===== Define and Deploy Aspects ===== +The **launcher.js** script and the **js** executable are included in the standard AspectScript distribution. 
-The aspects of AspectScript are pointcut-advices pairsThe pointcuts and advices are JavaScript functions. For instance, if you need to identify all executions of the **foo** function.  + 
-<code JavaScript+===== Define and Deploy Aspects (Under Construction)===== 
-AspectScript.after(AspectScript.Pointcuts.exec(foo)function(jp) { + 
-        alert("foo was executed"); +The aspects of AspectScript are just a pointcut-advice pairPointcuts and advices are plain JavaScript functions. For instance, if you need to identify all executions of the **foo** function.  
-});+ 
 +<code java
 +var pointcut = AspectScript.Pointcuts.exec(foo)
 +var advice   function() { 
 + alert("Foo was executed"); 
 +}
 +AspectScript.after(pointcut, advice);
 </code> </code>
  
 ===== For More Information ===== ===== For More Information =====
-You want to learn more about AspectScript, you can read the [[technical report|technical report]] + 
 +This page is still under construction.  Please see the [[examples|examples]] page if you want to learn more about AspectScript.
  
  
  • tutorial.1252357890.txt.gz
  • Last modified: 2009/09/25 16:01
  • (external edit)