- CoffeeScript 教程
- CoffeeScript - 主页
- CoffeeScript - 概述
- CoffeeScript - 环境
- CoffeeScript - 命令行实用工具
- CoffeeScript - 语法
- CoffeeScript - 数据类型
- CoffeeScript - 变量
- CoffeeScript - 运算符和别名
- CoffeeScript - 条件判断
- CoffeeScript - 循环
- CoffeeScript - 解析
- CoffeeScript - 函数
- CoffeeScript 面向对象
- CoffeeScript - 字符串
- CoffeeScript - 数组
- CoffeeScript - 对象
- CoffeeScript - 范围
- CoffeeScript - 展开
- CoffeeScript - 日期
- CoffeeScript - 数学
- CoffeeScript - 异常处理
- CoffeeScript - 正则表达式
- CoffeeScript - 类和继承
- CoffeeScript 高级
- CoffeeScript - Ajax
- CoffeeScript - jQuery
- CoffeeScript - MongoDB
- CoffeeScript - SQLite
- CoffeeScript 实用资源
- CoffeeScript - 快速指南
- CoffeeScript - 实用资源
- CoffeeScript - 讨论
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.
coffeescript_strings.htm
广告