Monday, September 10, 2012

Chaining pattern

Method chaining is a common technique for invoking multiple method calls in object-oriented programming languages. Each method returns an object (possibly the current object itself), allowing the calls to be chained together in a single statement (Wikipedia definition). This technique was made popular in several libraries, like jQuery.

Let's see JQuery example of method chaining:

Here is how we can implement method chaining in JavaScript (Calculator example):

No comments:

Post a Comment