目录

Show 例子

下表显示了少数比较运算符的别名。 假设A持有20而变量B持有20

操作者 别号
= =(等于) is A is B给你真实的。
!= =(不等于) isnt A isnt B给你假。

例子 (Example)

以下代码显示了如何在CoffeeScript中为比较运算符使用别名。 将此代码保存在名为comparison_aliases.coffee的文件中

a = 10
b = 20
console.log "The result of (a is b) is "
result = a is b
console.log result
console.log "The result of (a isnt b) is "
result = a isnt b
console.log result

打开command prompt并编译comparison_example.coffee文件,如下所示。

c:/> coffee -c comparison_aliases.coffee

在编译时,它为您提供以下JavaScript。

// Generated by CoffeeScript 1.10.0
(function() {
  var a, b, result;
  a = 10;
  b = 20;
  console.log("The result of (a is b) is ");
  result = a === b;
  console.log(result);
  console.log("The result of (a isnt b) is ");
  result = a !== b;
  console.log(result);
}).call(this);

现在,再次打开command prompt并运行CoffeeScript文件,如下所示。

c:/> coffee comparison_aliases.coffee

执行时,CoffeeScript文件生成以下输出。

The result of (a is b) is
false
The result of (a isnt b) is
true
↑回到顶部↑
WIKI教程 @2018