我正在尝试使用用 CoffeeScript 编写的 QUnit 运行一些单元测试,但似乎有一些保留字会导致问题,尤其是“不”。有没有办法逃避 CoffeeScript 保留字?这是一个演示问题的简单测试:
module "Sad face test"
test "will not compile", ->
not false, "holy crap this creates a syntax error :-("
这产生的错误是“第 3 行解析错误:意外的','”
我正在尝试使用用 CoffeeScript 编写的 QUnit 运行一些单元测试,但似乎有一些保留字会导致问题,尤其是“不”。有没有办法逃避 CoffeeScript 保留字?这是一个演示问题的简单测试:
module "Sad face test"
test "will not compile", ->
not false, "holy crap this creates a syntax error :-("
这产生的错误是“第 3 行解析错误:意外的','”
The best answer I have been able to find is to escape into JavaScript and alias the function:
notEqual = `not`
module "Sad face test"
test "will not compile", ->
notEqual false, "holy crap this creates a syntax error :-("
Although it looks like not
isn't a function within the latest version of QUnit, so in this specific instance you may not need to to escape a CoffeeScript reserved word.
该not
函数是全局的,所以它实际上是附加到的window
,对吧?那么,您可以只写而不是反引号转义
window.not
而不是not
; 或者
notEqual = window.not