JQuery - SyntaxError:保留字“this”无法分配

时间:2012-11-16 20:11:09

标签: javascript jquery coffeescript

我正在尝试在JQuery中循环变量并在以下Coffeescript中重新分配this的值。

$.each data.rows, ->
  completion_time = [this[0], new Date(new Date('Jan 01 2000').getTime() +  this[1])]
  this = completion_time

然而,这会产生以下错误消息:

  

SyntaxError:保留字“this”无法分配

在每次迭代中,this的值看起来像这样:

  

[“abc123”,12302103,1230132,1230123]

我要做的是将其重新分配给:

的值
  

[“abc123”,12302103]

我也试过分配this.value,没有骰子。有什么建议吗?

1 个答案:

答案 0 :(得分:5)

您无法重新分配this。您可以修改this以包含新数组中的元素

我无法忍受CoffeScript,所以我只是在JS中展示它

// Clear elements from the array
this.length = 0;
// Add each element in the new array
this.push.apply(this, completion_time);
相关问题