javascript AOP 實現(xiàn)ajax回調函數(shù)使用比較方便
更新時間:2010年11月20日 20:20:03 作者:
javascript AOP 實現(xiàn)ajax回調函數(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();
相關文章
javascript下用ActiveXObject控件替換word書簽,將內(nèi)容導出到word后打印
由于時間比較緊,沒多的時候去學習研究上述工具包,現(xiàn)在用javascript操作ActiveXObject控件,用替換word模板中的書簽方式解決。2008-06-06
JavaScript關于prototype實例詳解(超重點)
prototype是js里面給類增加功能擴展的一種模式,這篇文章主要介紹了JavaScript關于prototype(超重點),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-08-08

