Message from JavaScript discussions

May 2019

— Along with other deps

— 

Optionally in an object:

class Foo {
constructor(deps) {
Object.assign(this, deps);
}
}


then in initialization:

new Foo({ assertExists });

— But then I would create the function for every instance instead of having it on the class or?

— No?

— The function already exists

— It's just an extra instance prop

— Doesn't really matter since assertExists is mostly a pure function, but the ideal way is to dependency-inject everything

Message permanent page

— But what is the advantage of passing it as a prop instead of defining it on the class?

— Or what is the disadvantage of using it as static class method

— Defining it like this is direct coupling

— Means:
A) The instance can't be constructed with a different assertExists
B) assertExists can't be mocked

Message permanent page

— I use one assertExists utility for all classes