function order500(orderType, isPay, count) {
if (orderType === 1 && isPay) {
console.log('您中奖了100元');
} else {
return 'next';
}
}
function order200(orderType, isPay, count) {
if (orderType === 2 && isPay) {
console.log('您中奖了20元');
} else {
return 'next';
}
}
function orderDefault(orderType, isPay, count) {
if (count > 0) {
console.log('您已抽到10元');
} else {
console.log('谢谢参与');
}
}
function Chain(fn) {
this.fn = fn;
this.next = null;
}
Chain.prototype.setNext = function(next) {
this.next = next;
}
Chain.prototype.passRequest = function(next) {
let ret = this.fn.apply(this, arguments);
if (ret === 'next') {
this.next && this.next.passRequest.apply(this.next, arguments)
}
}
let chainOrder500 = new Chain(order500)
let chainOrder200 = new Chain(order200)
let chainOrderDefault = new Chain(orderDefault)
chainOrder500.setNext(chainOrder200)
chainOrder200.setNext(chainOrderDefault)
chainOrder500.passRequest(1, true, 500)
console