1

It is easy enough (for 90% of aop features) to do it without any support being the language itself, like in most dynamic languages like python and ruby. However, Dojo had direct support for it on 1.3.2. What happened in the latest versions? Did they remove it?

Is there another javascript aop library that should get more attention?

Daniel Ribeiro
  • 3,110
  • 3
  • 23
  • 49

4 Answers4

2

Given the flexible syntax candy available in Javascript, I'd imagine there would be a billion AOP libraries out there.

A quick Google search brought up the following:

... and another Stackoverflow question

Community
  • 1
  • 1
Sam Day
  • 1,713
  • 9
  • 17
2

dojox.lang.aspect is still there, still in use by serious projects. Nobody removed it. In fact I hope parts of it will be an important part of the upcoming Dojo 2.0.

What was the reason for your question? Couldn't find some links, or was it something else? Just let me know, and I'll help with that.

Update:

The API documentation link: http://dojotoolkit.org/api/dojox/lang/aspect.html

The link to my blog post about AOP (it is listed in your question: http://lazutkin.com/blog/2008/may/18/aop-aspect-javascript-dojo/) is still current, so you can use it as a general reference. I plan to migrate it to the official reference documentation.

Eugene Lazutkin
  • 43,776
  • 8
  • 49
  • 56
  • Couldn't find in the latest documentation. It made it seem like it was abandoned. – Daniel Ribeiro Sep 21 '10 at 01:51
  • Of course not. I'll investigate the doc problem. For now I am adding the API doc link to my answer. – Eugene Lazutkin Sep 21 '10 at 06:59
  • Great. It would be even greater if it was provided as a separate library outside dojo, but javascript projects, outside Nodejs ones, don't usually have modularity as a big concern. – Daniel Ribeiro Sep 21 '10 at 16:40
  • Dojo was originally conceived as a library of libraries. It still shows. For Dojo 2.0 we are working on a common module and package format, which can be adopted by other projects. So you wish may come true. ;-) – Eugene Lazutkin Sep 21 '10 at 21:33
  • OTOH nobody prevents other developers from porting any part of Dojo to other library or converting it to be standalone. It is definitely possible, and not hard as some people imagine. – Eugene Lazutkin Sep 21 '10 at 21:35
0

Well, you can try these decorators https://www.npmjs.com/package/ng-aspect that bring to TypeScript (ES2015/2016) real AOP experience. Just look at this code

import { Before, After, Pointcut } from "./aspect";

class Foo {
  @Pointcut
  bar(){
    console.log( "calling bar", arguments );
  }
}

class Advice {
  @Before( Foo, "bar" )
  preLog() {
    console.log( "calling pre-log", arguments );
  }

  @After( Foo, "bar" )
  postLog() {
    console.log( "calling post-log" );
  }
}

(new Foo()).bar( 1, 2, 3 );

// calling pre-log 1,2,3
// calling bar 1,2,3
// calling post-log
Dmitry Sheiko
  • 2,130
  • 1
  • 25
  • 28
0

Definitely any language will support AOP because is a technique, you should implement it by your self.

ES7 Decorators are awesome for AOP syntax, but there is no need to go typescript to get real AOP experience. Even ES5 can do it:

var Class = require("kaop").Class;

var Dummy = Class({
  someMethod: [ //decoratedMethod
    "subscribe","$inject", //befores
     function($$dep1){ 
       //method body 
     }, 
     "trigger: 'action'", //afters (advice with an argument) 
  ],
  anotherMethod: function(){
    /* method without advices */
  }
})

I suggest you to check my recent work which implements top AOP features, even async calls

https://github.com/k1r0s/kaop https://github.com/k1r0s/kaop-ts (Alpha) (if u love ES7 Decorators)

I also wrote an article explaining this tip

https://medium.com/@k1r0s/aspect-oriented-programming-in-javascript-es5-typescript-d751dda576d0#.3d04ziock

k1r0s
  • 359
  • 3
  • 14