Coffeescript-string-concat
提供:Dev Guides
CoffeeScript文字列-concat()
説明
このメソッドは、2つ以上の文字列を追加し、結果の文字列を返します。
構文
以下に、JavaScriptの* concat()*メソッドの構文を示します。 CoffeeScriptコードから同じメソッドを使用できます。
string.concat(string2, string3[, ..., stringN]);
例
次の例は、CoffeeScriptコードでJavaScriptの* concat()メソッドを使用する方法を示しています。 このコードを *string_concat.coffee という名前のファイルに保存します
str1 = "Hello how are you. "
str2 = "Welcome to Tutorials Point."
str3 = str1.concat str2
console.log "Concatenated String :" + str3
- コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c string_concat.coffee
コンパイル時に、次のJavaScriptが提供されます。
//Generated by CoffeeScript 1.10.0
(function() {
var str1, str2, str3;
str1 = new String("Hello how are you. ");
str2 = new String("Welcome to Tutorials Point.");
str3 = str1.concat(str2);
console.log("Concatenated String :" + str3);
}).call(this);
次に、*コマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。
c:\> coffee string_concat.coffee
CoffeeScriptファイルを実行すると、次の出力が生成されます。
Concatenated String :Hello how are you. Welcome to Tutorials Point.