Skip to main content
WolfShade
Legend
August 29, 2018
Question

JavaScript: function expression vs arrow function

  • August 29, 2018
  • 2 replies
  • 738 views

Hello, all,

I've only just started reading about arrow functions in JavaScript.  Not sure if I want to start using them, or not, but wanted to get a feel for how most of you prefer to code, function expression or arrow function?

V/r,

^ _ ^

    This topic has been closed for replies.

    2 replies

    pziecina
    Legend
    August 29, 2018

    I think the answers will depend very much on the age of the person answering, how long they have been coding in js, and how much they code in other languages.

    For me I tend to use function expressions, mainly because that is how I code, (and learned to) in C# so it is less confusing when switching between languages.

    Legend
    August 29, 2018

    pziecina  wrote

    I think the answers will depend very much on the age of the person answering, how long they have been coding in js, and how much they code in other languages.

    I think you're right - I'm an old fart so use old fart workflows......................................which work without all the fuss and confusion.....that's what I think anyway!!

    Legend
    August 29, 2018

    Im not using them yet because lm more familiar with the old way plus l think l can determine where the function is better, the arrow function seems to get lost within the rest of the code plus of course its not compatible if you need to support older  browsers.

    Old habits die hard, especially once lve been using something which then becomes habital.

    One thing which is good about them is when scoping is involved you dont have to do something like

    Iet self = this;

    self.name = self.value

    You can use this

    this.name = this.value

    B i r n o u
    Legend
    August 29, 2018

    I'm not sure to quite understand what you do mean when scoping without binding ?

    Legend
    August 29, 2018

    If l use this.blah within a set time out function for example or some other functions it usually doesnt work.

    I have to asign 'this' to a variable

    If l use the arrow function l can use 'this' without assigning it to a variable