Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zh-cn]: Update translation of String.includes() #14142

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ slug: Web/JavaScript/Reference/Global_Objects/String/includes

{{JSRef}}

**`includes()`** 方法执行区分大小写的搜索,以确定是否可以在另一个字符串中找到一个字符串,并根据情况返回 `true` 或 `false`。
**`includes()`** 方法执行区分大小写的搜索,以确定是否可以在一个字符串中找到另一个字符串,并根据情况返回 `true` 或 `false`。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no objection to the modification here

Copy link
Member Author

@JasonLamv-t JasonLamv-t Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原文的 ‘another’ 用于修饰后一个 ‘string’ 以令其区别于前一个 ‘string’,如果强行按照原文翻译,由于语序的问题,‘另一个’ 在 ‘一个’ 前面,这不符合习惯,而且没有裨益


{{EmbedInteractiveExample("pages/js/string-includes.html", "shorter")}}

Expand All @@ -23,14 +23,19 @@ includes(searchString, position)
- `position` {{optional_inline}}
- : 在字符串中开始搜索 `searchString` 的位置。(默认为 `0`。)

- `searchString`
- : 一个要在 `str` 中查找的字符串。[不能是正则表达式](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp#正则表达式的特殊处理)。所有非正则表达式的值都会被[强制转换为字符串](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#字符串强制转换),因此如果该参数被省略或传入 `undefined`,`includes()` 方法会在字符串中搜索 `"undefined"`,这通常不是你想要的。
- `position` {{optional_inline}}
- : 在字符串中开始搜索 `searchString` 的位置。默认值为 `0`。

### 返回值

如果当前字符串包含被搜寻的字符串,就返回 **`true`**,否则返回 **`false`**。
如果在给定的字符串中找到了要搜索的字符串(包括 `searchString` 为空字符串的情况),则返回 **`true`**,否则返回 **`false`**。

### 异常

- {{jsxref("TypeError")}}
- : 如果 `searchString` 是一个[正则表达式](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp#special_handling_for_regexes)
- : 如果 `searchString` [是一个正则表达式](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp#正则表达式的特殊处理),则会抛出

## 描述

Expand All @@ -41,13 +46,13 @@ includes(searchString, position)
`includes()` 方法是区分大小写的。例如,下面的表达式会返回 `false`:

```js
"Blue Whale".includes("blue"); // returns false
"Blue Whale".includes("blue"); // 返回 false
```

你可以通过将原字符串和搜索字符串全部转换为小写来解决这个约束:

```js
"Blue Whale".toLowerCase().includes("blue"); // returns true
"Blue Whale".toLowerCase().includes("blue"); // 返回 true
```

## 示例
Expand Down Expand Up @@ -75,7 +80,7 @@ console.log(str.includes("")); // true

## 参见

- [Polyfill of `String.prototype.includes` in `core-js`](https://github.com/zloirock/core-js#ecmascript-string-and-regexp)
- [`core-js` 中 `String.prototype.includes` 的 polyfill](https://github.com/zloirock/core-js#ecmascript-string-and-regexp)
- {{jsxref("Array.prototype.includes()")}}
- {{jsxref("TypedArray.prototype.includes()")}}
- {{jsxref("String.prototype.indexOf()")}}
Expand Down