dess_javascript 기술로 간단한 다자간 위임 구현

WBOY
풀어 주다: 2016-05-16 18:22:50
원래의
997명이 탐색했습니다.
复제대码 代码如下:

var SDelegate = function(f, b, c) {
if (b) {
this.asFunction_ = function() {
return f.apply(b, 인수);
}
} else {
this.asFunction_ = function() {
return f.apply(this, 인수);
}
}
this.method_ = f;
this.bind_=b;
this.continus = c;
}
SDelegate.composite = function(d) {
if (d.continus) {
var con = d.continus.composited_ = SDelegate.composite(d.continus);
var 메소드 = d.asFunction_;
return function() {
con.apply(this, 인수);
return method.apply(this, 인수);
}
} 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);
}
};
반환 함수(테스트, 데이터) {
var p = this;
if (test(this, data)) {
p = this.continus;
}
removeP(p, p.continus, test, data);
p.composited_ = null;
p를 반환합니다.
}
}();
SDelegate.prototype.append = function(f, b) {
새 SDelegate(f, b, this)를 반환합니다.
}

这个SDelegate user 起来可能会比较诡异,比如很多操值。Dess中,SDelegate主要用于一些特定场合,如DOM事件派发。
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!