首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >coffeescript中的数学计算中断

coffeescript中的数学计算中断
EN

Stack Overflow用户
提问于 2012-09-30 19:09:35
回答 1查看 150关注 0票数 1

我有一个用coffeescript编写的长方程,它在编译到JavaScript时将返回一个函数调用:

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:

代码语言: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)));

问题是这一部分:

代码语言:javascript
复制
((@uu[right] + @uu[left] + @uu[bottom] + @uu[top]) -4 * currU)

它转化为一个函数调用:

代码语言:javascript
复制
((this.uu[right] + this.uu[left] + this.uu[bottom] + this.uu[top])(-4 * currU))

有人能解释一下这是怎么回事吗。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-30 19:16:27

你想要这个

代码语言: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.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])’函数的一个参数。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12664166

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档