25

I find this notation everywhere in Webpack generated libs but I don't understand it :

var a = (0, _parseKey2.default)(something)

What does the (0, _parseKey2.default) stands for ? I don't remember seeing those coma separated expressions between parenthesis elsewhere that in function parameters, so maybe I am just missing something simple.

Thanks for your help.

AlexHv
  • 1,694
  • 14
  • 21
  • 3
    This is the [comma operator](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Comma_Operator). No clue though why webpack is generating stuff like this, but I have seen that, too. – Renke Grunwald Feb 20 '16 at 11:31

1 Answers1

44

This is to give _parseKey2.default the correct this (or, rather, no this at all), that is, to call it as an ordinary function, not a method. Consider:

var p = {
    f : function() {
        console.log(this)
    },
    x : "foo"
};

p.f();      // { f: ... x: foo }
(p.f)();    // { f: ... x: foo }
(0, p.f)(); // implicit global this

The comma expression is a more concise way to do this:

 var unbound = p.f;
 unbound();
georg
  • 211,518
  • 52
  • 313
  • 390