Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript `此`未在原型方法中绑定_Javascript_Ecmascript 6_Babeljs_Arrow Functions_Stealjs - Fatal编程技术网

Javascript `此`未在原型方法中绑定

Javascript `此`未在原型方法中绑定,javascript,ecmascript-6,babeljs,arrow-functions,stealjs,Javascript,Ecmascript 6,Babeljs,Arrow Functions,Stealjs,我有一个关于箭头函数的奇怪问题: 在原型方法中(本例中为es6类方法),箭头函数应具有此绑定的上下文,但在本例中,第一个lambda中的“this”未定义 apply(bookings) { if (!bookings.length) { return } bookings.forEach(booking=> { //this is undef here let matchingTimeSlot = this.timeSlots.f

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

在原型方法中(本例中为es6类方法),箭头函数应具有此绑定的上下文,但在本例中,第一个lambda中的“this”未定义

 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)

这是未定义的

请注意,您的调试工具可能在欺骗您
这个
实际上会被传输到
\u这个
或者类似的地方。您应该查看生成的JavaScript。我可以向您保证,它将使这个
(或其名称)指向正确的东西

这是未定义的


请注意,您的调试工具可能在欺骗您
这个
实际上会被传输到
\u这个
或者类似的地方。您应该查看生成的JavaScript。我可以向您保证,
\u此
(或其名称)将指向正确的东西。

请告诉我们您如何调用
应用
。我确信
这个
在arrow函数之外也是
未定义的
。arrow函数不应该将
这个
绑定到任何东西上。不,它们应该具有与其词法父函数相同的
this
。@Bergi在这一行
this
定义为:
bookings.forEach
你怎么知道的?你没有用它,是吗?你确定定义了
currentDaysBookings
吗?@Bergi我确定,我使用了一个调试器,是的
currentDaysBookings
定义了告诉我们如何调用
apply
,请。我确信
这个
在arrow函数之外也是
未定义的
。arrow函数不应该将
这个
绑定到任何东西上。不,它们应该具有与其词法父函数相同的
this
。@Bergi在这一行
this
定义为:
bookings.forEach
你怎么知道的?你没有用它,是吗?你确定定义了
currentDaysBookings
吗?@Bergi我确定,我使用了一个调试器,是的
currentDaysBookings
定义了吗?我注意到这是正确的,所以bug在babel中?为什么巴贝尔不把它传给这个?我怎么知道它是什么?所以现在我需要把我的代码从
this.timeSlots
改为
\u this.timeSlots
,这看起来很悲哀。好吧,我注意到这是正确的,那么bug就在babel中了?为什么巴贝尔不把它传给这个?我怎么知道它是_this?所以现在我需要将代码从
this.timeSlots
更改为
\u this.timeSlots
,这似乎很悲哀。。