0

Setting aside compatibility issues aside, when are we to use "function" and "=>"? Are we to completely replace "function" with "=>" in es6 compatible environments?

I guess I can see when you want "this" to be different context you wouldn't want arrow. But I genuinely don't see any other reason to use "function" keyword anymore and I would like to clarify this.

jk-kim
  • 966
  • 2
  • 10
  • 18
  • methods in object literals can't use them... – dandavis Jan 11 '16 at 23:02
  • See also http://stackoverflow.com/q/34361379/218196 – Felix Kling Jan 12 '16 at 05:07
  • @dandavis What do you mean by that? – CodingIntrigue Jan 12 '16 at 12:53
  • i mean that methods use `this`, and you can't use `this` in fat arrows like you can normal functions, so thing like `pretty:function(){return this.fName+" "+this.lName;},` don't work like you want them to. Same goes for generic functions like `function sum(n){"use strict"; return n+this;}`, which i use all the time with map/filter, `ex: [1,2,3].map(sum, 5);` – dandavis Jan 12 '16 at 16:55

0 Answers0