Behavioral pattern
Behavioral patterns are used to delegate responsibilities between objects. In the following section, we will discuss all four behavioral patterns mentioned previously, and how to implement them in JavaScript.
Chain of responsibility pattern
The chain of responsibility pattern provides a chain of objects executed in order as they are chained to fulfill any request. A good example for ASP.NET developers is the OWIN pipeline that chains the components or OWIN middleware together and is based on the appropriate request handler being executed:
Let's look into a very basic example that executes the chain of objects and displays the table for 2, 3 and 4:
<script> //Main component var Handler = function (table) { this.table = table; this.nextHandler = null; } //Prototype to chain objects Handler.prototype = { generate: function (count) { for (i = 1; i <= count; i++) { console.log(this.table + " X "...