`this` 未绑定在原型方法中

`this` is not being bound in prototype method

我有一些关于箭头函数的奇怪问题:

箭头函数应该在原型方法(在本例中为 es6 class 方法)中具有此绑定的上下文,但在本例中 'this' 在第一个 lambda 中是 undef

 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 正在从另一个 es6 class:

调用

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

this is undef here

请注意,您的调试工具可能在欺骗您。 this 实际上会被转译为 _this 或类似的东西。你应该看看生成的JavaScript。我可以向您保证,它将 _this(或任何名称)指向正确的东西。