1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-28 21:32:20 +00:00

修改string/contains方法改为includes

This commit is contained in:
Ruan Yifeng 2015-01-14 12:10:21 +08:00
parent 29149c7450
commit 4d044952dc

View File

@ -265,11 +265,11 @@ normalize方法可以接受四个参数。
不过normalize方法目前不能识别三个或三个以上字符的合成。这种情况下还是只能使用正则表达式通过Unicode编号区间判断。
## contains(), startsWith(), endsWith()
## includes(), startsWith(), endsWith()
传统上JavaScript只有indexOf方法可以用来确定一个字符串是否包含在另一个字符串中。ES6又提供了三种新方法。
- **contains()**:返回布尔值,表示是否找到了参数字符串。
- **includes()**:返回布尔值,表示是否找到了参数字符串。
- **startsWith()**:返回布尔值,表示参数字符串是否在源字符串的头部。
- **endsWith()**:返回布尔值,表示参数字符串是否在源字符串的尾部。
@ -279,7 +279,7 @@ var s = "Hello world!";
s.startsWith("Hello") // true
s.endsWith("!") // true
s.contains("o") // true
s.includes("o") // true
```
@ -291,7 +291,7 @@ var s = "Hello world!";
s.startsWith("o", 4) // true
s.endsWith("o", 8) // true
s.contains("o", 8) // false
s.includes("o", 8) // false
```