国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript AOP 實現ajax回調函數使用比較方便

2019-11-21 00:06:10
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

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();
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 资中县| 健康| 大足县| 杂多县| 玛沁县| 永善县| 台中市| 原阳县| 高陵县| 全椒县| 平邑县| 桂阳县| 锦屏县| 独山县| 荣成市| 东山县| 文成县| 晋宁县| 遂昌县| 江华| 沁阳市| 高台县| 桑植县| 铁力市| 若尔盖县| 通许县| 深圳市| 修文县| 金川县| 白玉县| 陕西省| 芦溪县| 都昌县| 色达县| 博兴县| 合江县| 青冈县| 汶川县| 嘉义县| 隆回县| 勃利县|