Message from JavaScript discussions

May 2019

— Currently I just import this function every time and use it as a static method

— 

Import { assertExists } from "helper";

class Foo {
constructor() {
}

static assertExists = assertExists;
}

— That's tight coupling

— But ehh

— How is this better?

import { AssertExists } from "helper";

class Foo extends AssertExists {
constructor () {
}
}

Message permanent page

— The correct way imo:

class Foo {
constructor(assertExists) {
this.assertExists = assertExists;
}
}

— Then you pass it down during initialization

— Along with other deps

— Optionally in an object:

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


then in initialization:

new Foo({ assertExists });

Message permanent page

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

— No?

— The function already exists