我有一个用coffeescript编写的长方程,它在编译到JavaScript时将返回一个函数调用:
CoffeeScript:
@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))有人能解释一下这是怎么回事吗。
发布于 2012-09-30 19:16:27
你想要这个
@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,vs - 4。
没有空格,编译器假设-4 * currU是‘(@uu[right] + @uu[left] + @uu[bottom] + @uu[top])’函数的一个参数。
https://stackoverflow.com/questions/12664166
复制相似问题