JavaScript Function Chaining
Function chaining under the hood
The aim of this piece is to help you understand functional chaining and jQuery, and to be able to incorporate similar behavior in simple JavaScript Functions.
This piece will cover:
- Understanding jQuery function chaining
- Implementing function chaining in custom JavaScript functions
Function chaining is a pattern in JavaScript where multiple functions are called on the same object consecutively. Using the same object reference, multiple functions can be invoked. It increases the readability of the code and means less redundancy.
We need multiple functions to accomplish all the functionality related to an entity. These functions can be defined in such a way that they can be chained together to accomplish the required results.
Understanding jQuery Functional Chaining
In HTML, we deal with DOM elements. Each DOM element has multiple properties and functionalities associated with it. Let's assume that for a single DOM element we need to make multiple manipulations, like…