dess中一個(gè)簡單的多路委托的實(shí)現(xiàn)
更新時(shí)間:2010年07月20日 01:14:09 作者:
這個(gè)SDelegate用起來可能會(huì)比較詭異,比如很多操作都要重新賦值。Dess中,SDelegate主要用于一些特定場合,如DOM事件派發(fā)。
復(fù)制代碼 代碼如下:
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);
}
這個(gè)SDelegate用起來可能會(huì)比較詭異,比如很多操作都要重新賦值。Dess中,SDelegate主要用于一些特定場合,如DOM事件派發(fā)。
相關(guān)文章
setTimeout內(nèi)不支持jquery的選擇器的解決方案
在JS中無論是setTimeout還是setInterval,在使用函數(shù)名作為調(diào)用句柄時(shí)都不能帶參數(shù),而在許多場合必須要帶參數(shù),這就需要想方法解決。2015-04-04
JavaScript 獲取當(dāng)前日期時(shí)間 年月日 時(shí)分秒的方法
這篇文章主要介紹了JavaScript 獲取當(dāng)前日期時(shí)間年月日時(shí)分秒的方法,通過案例代碼介紹了獲取當(dāng)前日期方法,代碼簡單易懂,需要的朋友可以參考下2023-10-10
fullpage.js全屏滾動(dòng)插件使用實(shí)例
這篇文章主要介紹了fullpage.js全屏滾動(dòng)插件使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
js 動(dòng)態(tài)校驗(yàn)開始結(jié)束時(shí)間的實(shí)現(xiàn)代碼
這篇文章主要介紹了js 動(dòng)態(tài)校驗(yàn)開始結(jié)束時(shí)間的實(shí)現(xiàn)代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05
一個(gè)簡單的全屏圖片上下打開顯示網(wǎng)頁效果示例
這是一個(gè)簡單的全屏圖片上下打開顯示網(wǎng)頁效果,源碼如下,喜歡的朋友可以練練手2014-07-07
javascript不同類型數(shù)據(jù)之間的運(yùn)算的轉(zhuǎn)換方法
這篇文章主要介紹了javascript不同類型數(shù)據(jù)之間的運(yùn)算的轉(zhuǎn)換方法,需要的朋友可以參考下2014-02-02

