aop

所属分类:工具库
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2015-09-09 13:53:40
上 传 者sh-1993
说明:  一个小型的面向方面编程JavaScript库,
(A small Aspect Oriented Programming JavaScript library,)

文件列表:
LICENSE (1079, 2015-09-09)
aop.js (1714, 2015-09-09)
package.json (569, 2015-09-09)

AOP === A small Aspect Oriented Programming JavaScript library How to install === npm install tiny-aop How to use === In our search for a simple AOP library in JavaScript we evaluated several solutions and decided to use Fredrik Appelberg's excellent [Aop.js](http://fredrik.appelberg.me/2010/05/07/aop-js.html). We found that instead of passing JavaScript objects into the namespaces parameter we needed to pass an object prototype in, so all instances of our object's methods were intercepted by the aspect. Only a couple of very minor modifications were needed for this, so credit is entirely due here to Fredrik's library. With his kind permission I have published our modified version of the library. How to use (assume 'cat' objects with prototype 'makeSound'...): var Aop = require("tiny-aop"); var Cat = function() { this.makeSound = function() { console.log('Meooowwww!'); }; }; Cat.prototype.test = function() { console.log('test-proto'); } var test = new Cat; Aop.before("test", function() { console.log('aop-test', arguments); }, [ Cat.prototype ]); Aop.before("makeSound", function() { console.log('aop-sound', arguments); }, [ test ]); test.makeSound(2, 56); test.test(); License: MIT

近期下载者

相关文件


收藏者