It is easy enough (for 90% of aop features) to do it without any support being the langua开发者_如何学运维ge 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?
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:
- Aspect JS
- jQuery AOP
... and another Stackoverflow question
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.
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
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
精彩评论