Js 职责链模式 简单理解

2023-05-25,,

js 职责模式 的简单理解。大叔的代码太高深了,不好理解。

function Handler(s) {
this.successor = s || null;
this.handle = function () {
if (this.successor) {
this.successor.handle();
}
}
} var app = new Handler({
handle: function () {
console.log('app handle');
}
}); var dialog = new Handler(app);
dialog.handle = function () {
console.log('dialog before ...');
app.handle(this);
console.log('dialog after ...');
};
var button = new Handler(dialog);
button.handle = function () {
console.log('button before ...');
dialog.handle(this);
console.log('button after ...');
}; button.handle();

输出结果:

button before ...
dialog before ...
app handle
dialog after ...
button after ...

引用  http://www.cnblogs.com/TomXu/archive/2012/04/10/2435381.html

Js 职责链模式 简单理解的相关教程结束。

《Js 职责链模式 简单理解.doc》

下载本文的Word格式文档,以方便收藏与打印。