NPM Package Study — delegates (6 million weekly download, a single js file)

Alick Wong
4 min readJun 15, 2019

Introduction

Single js file package with 6,530,182 weekly download, interesting. It is a node method and accessor delegation utility which helps delegation in OOP. Let take a look whats inside this package.

What is Delegation?

Here is a great example to understand delegation by Bozho in stackoverflow:

public class Car {
private Engine engine = new Engine(); //or inject it externally
public void start() {
engine.start();
}
}

In this example the Car delegates to the underlying Engine. The user of the car cannot directly start the engine (unless he is a mechanic). But he can tell the car to start, and the car in turn tells the engine to start.

You’d want to use it whenever you use object composition and you need to use a method of one of the composing objects. In that case you create a method that delegates to it.

--

--

Alick Wong

AWS Solutions Architect. Former co-founder of a game studio. Web Developer. Passionate about web technology. https://www.linkedin.com/in/alick-wong