Skip to content

PalashSJain/Aspect-Oriented-JavaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aspect Oriented Programming in JavaScript

AspectJ like advices can be utilized in JavaScript with the use of Aspect Oriented JavaScript.

Create Pointcut object

// This creates pModifyAlert Pointcut object for 'alert' functionality of 'window' context
var pModifyAlert = new Pointcut("alert", window);
// This creates a thingPointcut for the function 'someFunction' of the class Thing.prototype
var thingPointcut = new Pointcut("someFunction", Thing.prototype);

Advices supported

  • before
var pModifyAlert = new Pointcut("alert", window);
pModifyAlert.before(function(){
    console.log("This writes a message to console and then throws the alert message.");
});
  • around
var pModifyAlert = new Pointcut("alert", window);
pModifyAlert.around(function(){
    console.log("Replaced alert with console.log");
    console.log("The message was: " + pModifyAlert.arguments()[0]);
});
  • after
var pModifyAlert = new Pointcut("alert", window);
pModifyAlert.after(function(){
    console.log("This throws the alert message and then writes a message to console.");
});

About

Implementing AspectJ like advices in JavaScript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published