作家
登录

javascript AOP 实现ajax回调函数使用比较方便

作者: 来源:www.28hudong.com 2013-03-30 01:10:36 阅读 我要评论

复制代码 代码如下: function actsAsDecorator(object) { object.setupDecoratorFor = function(method) { if (! ('original_' + method in object) ) { object['original_' + method] = object[method]; object['before_' + method] = [ ]; object['after_' + method] = [ ]; object[method] = function() { var i; var b = this['before_' + method]; var a = this['after_' + method]; var rv; for (i = 0; i < b.length; i++) { b[i].call(this, arguments); } rv = this['original_' + method].apply(this, arguments); for (i = 0; i < a.length; i++) { a[i].call(this, arguments); } return rv; } } }; object.before = function(method, f) { object.setupDecoratorFor(method); object['before_' + method].unshift(f); }; object.after = function(method, f) { object.setupDecoratorFor(method); object['after_' + method].push(f); }; } /** Invoking */ function Test(){ this.say1 = function(s){ alert(s); } this.say2 = function(s){ alert(s); } } var t = new Test(); actsAsDecorator(t); t.before("say1",beforeHander); t.after("say2",afterHander); test();

  推荐阅读

  基于jquery的一个OutlookBar类,动态创建导航条

图示效果:演示地址:http://demo.jb51.net/js/menu_jquery/index.html下载地址:http://xiazai.jb51.net/201011/yuanma/menu_jquery.rarOutlookBar.js 复制代码 代码如下: function OutlookBar(targetName)//targ>>>详细阅读


本文标题:javascript AOP 实现ajax回调函数使用比较方便

地址:http://www.17bianji.com/kaifa2/JS/25388.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)