Git Product home page Git Product logo

attache.js's Introduction

build status Attache.js

Javascript implementation of Aspect Oriented Programming paradigm, enclosed in Node.js module

How to use:

var attache = require('attache.js');

attache.after(some_object, "some_object_function", function() {
	// Code which will be executed _after_ some.object.some_function() call	
});

attache.once_after(some_object, "some_object_function", function() {
	// Code which will be executed _only once_ after some.object.some_function() call	
});

// Removing aspect function
// Note: basically, we need to have stored aspect function in the value to pass it properly to remove function
attache.remove_after(some_object, some_object_function, aspect_function);

attache.before(some_object, "some_object_function", function() {
	// Code which will be executed _before_ some.object.some_function() call	
});

attache.once_before(some_object, "some_object_function", function() {
	// Code which will be executed _only once_ before some.object.some_function() call	
});

// Removing aspect function
// Note: basically, we need to have stored aspect function in the value to pass it properly to remove function
attache.remove_before(some_object, "some_object_function", aspect_function);

Example:

attache = require('attache.js');

var obj = {
  test: function(x) { return x; }
};

var fake = function() {
  var fake_val = 100;
  attache.before(obj, "test", function() {
  	console.log(fake_val);
	console.log(arguments);    
  });
}

fake();
console.log(obj.test(2, 3, 4));
Output:
100
{ '0': 2, '1': 3, '2': 4 }
2

attache.js's People

Contributors

rodzyn avatar

Stargazers

Sepand Haghighi avatar Crew Moss avatar Brad Pillow avatar Frank Eriksson avatar node-migrator-bot avatar Todd Bashor avatar Alessandro Mascherpa avatar  avatar Józef Chraplewski avatar Bartlomiej Niemtur avatar Dominik Fijaś avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

aoj

attache.js's Issues

expressjs with attachejs

Hi I can't send a git message, so I decided to talk with you here about this module.

Do you know how can I use Attache.js on Express.js Routes?

Like Rails Cancan for example, when I need to set a function to do some validation before pass to a route.

Could you show me a basic tutorial using your attache.js?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.