화살표 기능에 이상한 문제가 있습니다.
화살표 함수는 프로토 타입 메서드 (이 경우 es6 클래스 메서드)에있을 때이 바인딩의 컨텍스트를 가져야하지만이 경우 'this'는 첫 번째 람다 내부에서 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);
이것은 여기 undef입니다
디버그 도구가 거짓말을 할 수 있습니다. this
실제로 _this
또는 이와 비슷한 것으로 변환됩니다. 생성 된 JavaScript를 봐야합니다. 나는 그것이 _this
옳은 것을 가리킬 것이라고 확신 할 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다