Chain of Responsibility
A way of passing a request between a chain of objects

Last updated
A way of passing a request between a chain of objects

Last updated
EX: // one or more receivers in the chain handles a request
var Request = function(amount) {
this.amount = amount;
console.log("Requested: $" + amount + "\n");
}
Request.prototype = {
get: function(bill) {
var count = Math.floor(this.amount / bill);
this.amount -= count * bill;
console.log("Dispense " + count + " $" + bill + " bills");
return this;
}
}
function run() {
var request = new Request(378);
request.get(100).get(50).get(20).get(10).get(5).get(1);
}
run();