javascript AOP 實現(xiàn)ajax回調(diào)函數(shù)使用比較方便
更新時間:2010年11月20日 20:20:03 作者:
javascript AOP 實現(xiàn)ajax回調(diào)函數(shù)使用比較方便,需要的朋友可以參考下。
復制代碼 代碼如下:
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();
相關文章
js取兩個數(shù)組的交集|差集|并集|補集|去重示例代碼
求兩個集合的補集、交集、差集、并集等等在實際應用中經(jīng)常會使用到,下面與大家分享下具體的實現(xiàn)代碼,感興趣的朋友可以參考下,希望對大家有所幫助2013-08-08利用原生js實現(xiàn)html5小游戲之打磚塊(附源碼)
這篇文章主要給大家介紹了關于利用原生js實現(xiàn)html5小游戲之打磚塊的相關資料,這是最近工作遇到的一個小需求,文中通過示例代碼介紹的非常詳細,并分享了完整的源碼供大家參考學習,需要的朋友們下面隨著小編來一起學習學習吧。2018-01-01JavaScript Serializer序列化時間處理示例
JavaScriptSerializer序列化時間后會把時間序列化成N進制的鬼數(shù)據(jù) ,下面有個示例,需要的朋友可以了解下2014-07-07用js實現(xiàn)before和after偽類的樣式修改的示例代碼
本篇文章主要介紹了用js實現(xiàn)before和after偽類的樣式修改的示例代碼,具有一定的參考價值,有興趣的可以了解一下2017-09-09