0

I have some weird issue an arrow function:

Arrow functions are supposed to have a context of this bound when in a prototype method (es6 class method in this case), but in this case the 'this' is undef inside the 1st lambda

 apply(bookings) {
    if (!bookings.length) {
      return
    }
    bookings.forEach(booking=> {

  //this is undef here

      let matchingTimeSlot = this.timeSlots.find(item=>item.bookingDate.isSame(booking.bookingDate))
    })

apply is being called from another es6 class:

this.days[i].apply(currentDaysBookings);

basarat
  • 261,912
  • 58
  • 460
  • 511
SuperUberDuper
  • 9,242
  • 9
  • 39
  • 72

1 Answers1

2

this is undef here

Please note that your debug tools might be lying to you. this will actually get transpiled to _this or something like that. You should look at the generated JavaScript. I can assure you that it will have _this (or whatever its called) pointing to the right thing.

basarat
  • 261,912
  • 58
  • 460
  • 511