1
var log = (0, _lodash.memoize)(function (message) {
  console.log((0, _ansicolors.red)('WARNING:'), message);
});

I am facing difficulty in understanding the above code. This code was written in JavaScript.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Vasu
  • 129
  • 2
  • 9
  • Is it the [comma operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator) which you're asking about? – 4castle Feb 14 '17 at 07:14
  • my understand is that a function is passed to lodash memoize method as parameter and what that '0' is doing? i may be wrong... – Vasu Feb 14 '17 at 07:19
  • 2
    Perhaps [this question](http://stackoverflow.com/q/41529801/5743988) will show what purpose the `0` might have. Hint: the zero could have been any value. It's the comma which has special behavior. – 4castle Feb 14 '17 at 07:23
  • @4castle . Great example. – kawadhiya21 Feb 14 '17 at 07:25
  • you may have here http://stackoverflow.com/questions/36076794/does-the-comma-operator-influence-the-execution-context-in-javascript a look too. – Nina Scholz Feb 14 '17 at 07:33
  • Thanks @NinaScholz – Vasu Feb 14 '17 at 07:38

1 Answers1

1

Basically the code (0, _lodash.memoize) eliminates the need to make a new instance and directly gives you the value of function rather than reference.

kawadhiya21
  • 2,458
  • 21
  • 34