Tutorial

Overview

This tutorial is a guide to working at the code level with AspectJS v1.1. It starts with first principles, and is a guide to implementing fine-grained functionality with the library and its adjuncts, not an exploration of why doing that might be useful in a given context.

Given this, it does not explore the application of the technology in the sense of application design, or within the scope of Aspect-Oriented Programming as an approach to software development. Indeed, some of the principles explained may have no useful application, while others may have unrealised potential.

Similarly, the tutorial explores aspects of JavaScript itself only incidentally, and is not a guide to the language. Given this, you should consult a good reference on JavaScript wherever language-specific concepts that require further explanation are mentioned.

The code examples are included (with the same numbering) as part of the distribution package. To experiment with the examples yourself, simply decompress the zip file, follow the relevant instructions in Read_Me.txt, and go from there.

Note that the examples given are deliberately simple, which makes most of them somewhat dull and uninteresting in themselves. The aim, however, is to ensure that the key principle under consideration is shown clearly, and is not obscured by other issues in the code.

Getting Started

Importing the AJS Object

Applying Prefixes
How does it Work?
Considerations

Applying Suffixes
Applying Wrappers
Symmetric Wrappers

Using Inline Affix-Function Definitions
Parameterising Affix Application

Specifying Execution-Maxima

Arguments
and
Results

Passing Arguments to Interceptees
Returning Results from Interceptees

Interceptees and Exceptions
Affixes and Exceptions

Interceptee Arguments and Affixes
Static Affix-Function Arguments
Interceptee Return-Values and Suffixes

Affix
and Wrapper Objects

Affix Objects
Wrapper Objects

Affix Suspension and Resumption
Removing Affixes
Affix-Lifetime Rationale

Setting Execution-Maxima
Getting Execution-Maxima

Getting/Setting Func and Arg Parameters
Affix/Wrapper-Object Differences

Multiple Affixes

Adding New Affixes
Using addBefore/addAfter
Adding Affixes through Wrappers

Using Interceptee Methods

Multiple Prefix Function-Signatures
Multiple Suffix Function-Signatures

Iterating across Affix Sets
Adding New Affix-Properties
Promoting and Demoting Affixes

At the
Coal-Face

Intercepting User-Defined Object-Methods
Intercepting Object-Literal Methods
Intercepting Built-In Type Methods

Intercepting User-Defined Constructors
Intercepting Native/Built-in Constructor-Calls
Intercepting Exceptions

Intercepting Prototype Functions
Prototype Functions as Affixes

Intercepting Event-Handlers

Reflexion and Recursion

Recursive Interceptees
Intercepting Anonymous Functions
Intercepting Prefixes and Suffixes

Self-Intercepting Interceptees
Self-Affixing Interceptees

Self-Setting Affixes

Advanced Issues

Using 'call' and 'apply'
Replacing Interceptee References
Inner Functions
Closures as Affixes
Object-Property Enumeration

Debugger Call-Stacks
AspectJS and JSLint
Compression and Obfuscation
AspectJS on Non-Browser Platforms

Using aJS_DbC

Using aJS_DbC
Argument Checking in Action
Signature Augmentation
Detecting Redundant Affix-Object Calls
Calling aJS_DbC Redundantly

Using AJS_Logger

Importing AJS_Logger

onMCall
onMRtn

Enabling Logging
Suspending and Resuming

Using AJS_Logger with aJS_DbC