0

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

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

但是,这会产生以下错误消息:

语法错误:不能分配保留字“this”

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

[“abc123”, 12302103, 1230132, 1230123]

我正在尝试做的是将其重新分配给以下值:

[“abc123”,12302103]

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

4

1 回答 1

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);
于 2012-11-16T20:14:50.343 回答