0

I try to implement Babel in my javascript application but I've got a problem with a particular syntax.

Old Javascript code = this refer to li current element

var li = $('<li/>').attr('role', 'presentation')
        .appendTo(navTabs).addClass( function() {
          if ($(this).is(':first-child')) {
            return 'active';
          }
        });

Babel code with arrow function = this is undefined

var li = $('<li/>').attr('role', 'presentation')
        .appendTo(navTabs).addClass( ()=> {
          if ($(this).is(':first-child')) {  // This is undefined
            return 'active';
          }
        });

How can I make this work with Babel arrow syntax ?

bugyt
  • 616
  • 4
  • 11
  • 2
    You can't. Just don't try to use an arrow function when you don't need one. There's nothing wrong with function expressions in ES6. – Bergi Apr 23 '16 at 15:59
  • Hum okay, more complex than what I thought. Thank you. – bugyt Apr 23 '16 at 16:02

0 Answers0