Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我用 Coffeescript 1.3.3 打开一个 REPL 并输入:
y ?= 5
或者
y = 5 y ||= 6
我收到一个 y 未定义的错误...用于编译最后一个有效,但第一个仍然错误..这是预期的吗?
coffee> y = 5 5 coffee> y ||= 6 Error: In repl, the variable "y" can't be assigned with ||= because it has not been defined.
这是因为每次评估都涉及单独的编译。解决方法是将其作为全局对象的属性进行访问。
coffee> y = 5 5 coffee> global.y 5 coffee> @y 5 coffee> @y &&= 6 6 coffee> y 6