4
monnef
6y

TIL following two lines are NOT the same in JS with webpack, even though logically they should be - it should be just an application of an eta reduction... First line works, second one crashes, probably because mysteriously executed too soon, before obj is initialized.

export const t = (...args) => obj.t(...args);
export const t = obj.t;

Sometimes I really hate JavaScript magic.

Comments
  • 3
    No idea what’s going on, but I’ll give it an upvote because I hate JS.
  • 0
    Both lines should re-export same function - first creates a new function which calls desired function named "t", second line uses the function directly (simple assignment).

    The error message was quite cryptic (from a library). Tomorrow I'll try bind, it might be the problem (library was used in static context, but who knows what they are doing inside, I don't think using "this" in static context is a good practise, but I might be wrong).
Add Comment