数学计算在咖啡脚本中断



我有一个用coffeescript写的长方程,当编译为JavaScript时,它会在函数调用中出现:

咖啡脚本:

@u[idx] = @max(0, currU + t * ((@dU * ((@uu[right] + @uu[left] + @uu[bottom] + @uu[top]) -4 * currU) - d2) + currF * (1.0 - currU)))

JavaScript:

this.max(0, currU + t * ((this.dU * ((this.uu[right] + this.uu[left] + this.uu[bottom] + this.uu[top])(-4 * currU)) - d2) + currF * (1.0 - currU)));

问题是这部分:

((@uu[right] + @uu[left] + @uu[bottom] + @uu[top]) -4 * currU)

这变成了一个函数调用:

((this.uu[right] + this.uu[left] + this.uu[bottom] + this.uu[top])(-4 * currU))

有人可以解释一下这里发生了什么。

你想要这个:

@u[idx] = @max(0, currU + t * ((@dU * ((@uu[right] + @uu[left] + @uu[bottom] + @uu[top]) - 4 * currU) - d2) + currF * (1.0 - currU)))

编译为:

this.u[idx] = this.max(0, currU + t * ((this.dU * ((this.uu[right] + this.uu[left] + this.uu[bottom] + this.uu[top]) - 4 * currU) - d2) + currF * (1.0 - currU)));

愚蠢的小问题是-4,与- 4

如果没有空格,编译器假定-4 * currU"函数"的参数,(@uu[right] + @uu[left] + @uu[bottom] + @uu[top])

最新更新