尝试使用 coffeescript 和 Rails 3.1.0.rc4。有这个代码:
yourMom = (location) ->
console.log location
yourMom "wuz hur"
当页面加载时,这会正确输出“wuz hur”。但是当我尝试打电话时
yourMom("wuz hur")
从 chrome js 控制台(我有时会测试正常的 JS 函数),我得到一个“ReferenceError: yourMom is not defined”
coffeescript 生成的函数可以这样使用吗?
最佳答案
共享全局方法/变量的一种更简单的方法是使用@,意思是这个。
@yourMom = (location) ->
console.log location
yourMom "wuz hur"
更好的语法和更容易阅读,但我不鼓励你创建全局方法/变量
关于javascript - 从控制台调用 coffeescript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6756044/