如何在 javascript 中将我的胖箭头函数转换为 "normal" 函数



我只是想将其转换为普通的JS功能,而没有" fat Arrow"。

我希望身体=>成为正常功能。

我该如何写?

代码的摘要

fetch(this.JobExecEndpoint)
  .then(response => response.json())
  .then(body => {
    this.cleanStartTime = moment(body[0].time_start);
    this.cleanEndTime = moment(body[0].time_end);
    this.cleanDuration = this.calculateDuration(
      this.cleanStartTime,
      this.cleanEndTime
    );

// Hold a reference to "this" object inside a variable else you won't be able to access it using the "this" inside the callback function
var that = this; 
fetch(this.JobExecEndpoint).then(function(response)
{
     return response.json();
})
.then(function(body)
{
    that.cleanStartTime = moment(body[0].time_start);
    that.cleanEndTime   = moment(body[0].time_end);
    that.cleanDuration  = that.calculateDuration (
        that.cleanStartTime,
        that.cleanEndTime
    );
});

我希望这会有所帮助,让我知道您是否有任何问题:(

相关内容

最新更新