我有一些奇怪的问题是箭头函数:
在原型方法(本例中为 es6 类方法)中,箭头函数应该具有 this 绑定的上下文,但在本例中,'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 类调用:
this.days[i].apply(currentDaysBookings);