DEV Community

Sharu
Sharu

Posted on

Chaining in Javascript

Chaining is a means of simplifying the process to map, filter, extrapolate or reduce the data in a effective and user friendly manner.

Being widely utilized in Javascript libraries in the early days with Jquery and Underscore.js, its usage even in the present highly benefits many modern Javascript Libraries and Frameworks like React, Vue and Angular in making applications which are simple to design, keeping data abstract and code more modular.

Though the terminology might not be frequently used, one would have come across this to filter or map data sets. Backbone of Data Analytical and streaming applications is based out of this concept ( Eg: MapReduce in distributed file system processing)

One can build custom libraries based on its ease of implementing one using Javascript Objects. In fact all the inbuilt functions from Prototype Inheritance that Javascript Arrays and Objects provide is based out of Chaining. Example is as shown below

Snap a: Chaining process using Javascript Object

let chain = {
  result: 0,
  sum: function (param) {
    this.result = this.result + param;
    return this;
  },
  sub: function (param) {
    this.result = this.result - param;
    return this;
  },
  mul: function (param) {
    this.result = this.result * param;
    return this;
  },
  print: function () {
    console.log(`Result = ${this.result}`);
  },
};

chain.sum(5).mul(50).print();
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (1)

Collapse
 
reacthunter0324 profile image
React Hunter

god article

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more