CoffeeScript 字符串 - concat()
描述
此方法添加两个或多个字符串并返回结果字符串。
语法
下面给出的是 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.

