0

I know the differences between functions defined by arrow notation vs older/regular function declaration as laid out nicely in this post: Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?.

Namely:

  1. Arrow functions bind this to parent execution context implicitly
  2. Arrow functions cannot be used as constructors
  3. You can't name function expressions using arrow syntax
  4. Some other things such as using arguments (that I didn't know existed anyway)

In practical terms, is there any difference between using arrow function syntax / older function syntax for IIFEs? i.e.:

(function(context) {...})(this);

VS

((context) => {...})(this);

It doesn't seem like there are...

Also. As mentioned in an answer to: https://stackoverflow.com/a/38951021/3114742, there is mention that IIFEs are bad practice. But I quite like them... Is there a legitimate reason to avoid them?

Zach Smith
  • 8,458
  • 13
  • 59
  • 133
  • 1
    It seems to me you are overly sensitive and are trying to do right by everybody. Your quoted Medium article merely states, that the block constructs and `let` variable assignments of ES6 can be used instead of IIFE. But it does not condemn them to be "bad". – Carsten Massmann Mar 11 '18 at 08:44
  • I would consider IIFE a good practice when following functional paradigms, otherwise it might be confusing to a teammate not coming from a js background. And you already listed all of the differences and none of them applies to your snippet so dont you know the answer yourself? – Jonas Wilms Mar 11 '18 at 08:53
  • Regarding "*IIFEs are bad practice*", the [answer you referenced](https://stackoverflow.com/a/38951021/3114742) makes an unsupported statement. The [article referenced](https://medium.freecodecamp.org/5-javascript-bad-parts-that-are-fixed-in-es6-c7c45d44fd81) simply points out that ECMAScript 2015 features can be used as an alternative, not that IIFEs are "bad practice". – RobG Mar 11 '18 at 09:04
  • Yes @JonasW. - assuming my understanding of JavaScript in this regard is correct, then I do know the answer. But it's this understanding that I'm checking... – Zach Smith Mar 11 '18 at 10:11

0 Answers0