Coffeescript-comparison-aliases
提供:Dev Guides
比較演算子のエイリアス
次の表に、いくつかの比較演算子のエイリアスを示します。 A が 20 を保持し、変数 B が 20 を保持するとします。
Operator | Alias | Example |
---|---|---|
= = (Equal) | is | A is B gives you true. |
!= = (Not Equal) | isnt | A isnt B gives you false. |
例
次のコードは、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
- コマンドプロンプト*を開き、以下に示すように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);
次に、*コマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。
c:/> coffee comparison_aliases.coffee
CoffeeScriptファイルを実行すると、次の出力が生成されます。
The result of (a is b) is
false
The result of (a isnt b) is
true