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

首頁 > 編程 > JavaScript > 正文

dess中一個簡單的多路委托的實現

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

var SDelegate = function(f, b, c) {
if (b) {
this.asFunction_ = function() {
return f.apply(b, arguments);
}
} else {
this.asFunction_ = function() {
return f.apply(this, arguments);
}
}
this.method_ = f;
this.binding_ = b;
this.continus = c;
}
SDelegate.composite = function(d) {
if (d.continus) {
var con = d.continus.composited_ = SDelegate.composite(d.continus);
var method = d.asFunction_;
return function() {
con.apply(this, arguments);
return method.apply(this, arguments);
}
} else {
return d.asFunction_;
}
}
SDelegate.prototype.call = function() {
if (!this.composited_) this.composited_ = SDelegate.composite(this);
return this.composited_.apply(arguments[0], Array.prototype.slice.call(arguments, 1));
}
SDelegate.prototype.remove = function() {
var removeP = function(parent, item, test, data) {
if (!item) return;
parent.composited_ = item.composited_ = null;
if (test(item, data)) {
parent.continus = item.continus;
removeP(parent, item.continus, test, data);
} else {
removeP(item, item.continus, test, data);
}
};
return function(test, data) {
var p = this;
if (test(this, data)) {
p = this.continus;
}
removeP(p, p.continus, test, data);
p.composited_ = null;
return p;
}
}();
SDelegate.prototype.append = function(f, b) {
return new SDelegate(f, b, this);
}

這個SDelegate用起來可能會比較詭異,比如很多操作都要重新賦值。Dess中,SDelegate主要用于一些特定場合,如DOM事件派發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广水市| 苗栗市| 聊城市| 苍梧县| 陆丰市| 南宁市| 东明县| 德昌县| 海晏县| 鄂托克旗| 利津县| 泰宁县| 盖州市| 遂昌县| 句容市| 新巴尔虎左旗| 松潘县| 德安县| 安化县| 海阳市| 建宁县| 彩票| 美姑县| 平潭县| 百色市| 会昌县| 大竹县| 广安市| 堆龙德庆县| 靖西县| 滁州市| 德清县| 台东县| 泾源县| 鱼台县| 钟山县| 蒲城县| 永和县| 同江市| 体育| 马龙县|