DEV Community

Discussion on: Dependency Injection in JavaScript

 
kayis profile image
K • Edited

Ah, got it.

I probably would have implemented with a curried function.

const createFoo = wow => (data: PayLoad) => {
  const metric = wow(data.x);
  ...
}

in the regular place I'd use

foo = createFoo(wowGlobal);

and for testing something different, but I guess your way works too, it's just a bit more implicit.

Thread Thread
 
restuta profile image
Anton Vynogradenko • Edited

To be annoyingly pedantic, createFoo above is not a curried function, because it can't be called like createFoo(wow, data) and like createFoo(wow, data) at the same time, it's a higher order function with aurity of 1

Thread Thread
 
kayis profile image
K

I allow it!