GithubHelp home page GithubHelp logo

aop.js's Introduction

aop.js

Implicit events and aspect oriented programming (AOP).

Amusing Background

I attended day one of a compiler design course taught by Gregor Kiczales. Not knowing he was the originator of AOP, I shared my opinion that I disliked the notation used by his implementation, AspectJ. After a moment of tension, he proceeded to tell me that we were stuck with this sort of notation until we were to "start from scratch" (referring to syntax paradigms, I'm left to suppose).

I dropped the course and took graphics instead, so be forwarned: I may not know anything about aspect oriented programming.

Implicit Events

Certain frameworks let us have custom events, something like this.

var some_observable = new Observable({
    events: ['custom_event']
});

some_observable.on('custom event', function(){
    respond_to_event();
    // ...
}, scope);

observable.fireEvent('custom event');

Without having certain heavy frameworks, aop.js gives you something nearly equivalent, but more flexible.

var some_function = AOP(function(){
    
})

some_function.on(function(){
    respond_to_event();
});

some_function();

That is, your custom event fires implicitly when your function is called. This particular behaviour is the part of AOP I've found useful. However, in an attempt to do some justice to traditional AOP, here's some VERY BASIC "crosscutting", which is a core part of the AOP paradigm.

var animalRenderer = {
    drawDog: function(){
        // queue a dog shape to be rendered.
    },
    
    drawHorse: function(){
        // queue a horse shape to be rendered.
    }
};

// Automatically perform graphics processing without draw() functions knowing about it.
AOP.crosscut(animalRenderer, /^draw.*/, {

    cb:function(){
        // apply queued changes to canvas.
    },
    
    when: 'after'
    
});

aop.js's People

Contributors

countable avatar

Stargazers

高云 墨智 avatar  avatar

Watchers

 avatar  avatar

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.