javascript职责链模式

javascript职责链模式

 function GrandParent (child) {
     if (child) {
         this.child = child;
     }
 }
 GrandParent.prototype.work = function (task) {
     this.child.work(task);
 }
 
 function Parent (child) {
     if(child) {
         this.child = child;
     }
 }
 Parent.prototype.work = function (task) {
     this.child.work(task);
 }
 function GrandChild (task) {

 }
 GrandChild.prototype.work = function (task) {
     console.log(task);
 }
 const begin = new GrandParent(new Parent(new GrandChild()));
 begin.work('examination');

你可能感兴趣的:(前端,javascript)