-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ slug: Web/JavaScript/Reference/Global_Objects/String/includes | |||||
|
||||||
{{JSRef}} | ||||||
|
||||||
**`includes()`** 方法执行区分大小写的搜索,以确定是否可以在另一个字符串中找到一个字符串,并根据情况返回 `true` 或 `false`。 | ||||||
**`includes()`** 方法执行区分大小写的搜索,以确定是否可以在一个字符串中找到另一个字符串,并根据情况返回 `true` 或 `false`。 | ||||||
|
||||||
{{EmbedInteractiveExample("pages/js/string-includes.html", "shorter")}} | ||||||
|
||||||
|
@@ -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`**。 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里的主被动语态容易造成混淆,我再修改一下
JasonLamv-t marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
### 异常 | ||||||
|
||||||
- {{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#正则表达式的特殊处理),则会抛出。 | ||||||
|
||||||
## 描述 | ||||||
|
||||||
|
@@ -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 | ||||||
``` | ||||||
|
||||||
## 示例 | ||||||
|
@@ -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()")}} | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原文的 ‘another’ 用于修饰后一个 ‘string’ 以令其区别于前一个 ‘string’,如果强行按照原文翻译,由于语序的问题,‘另一个’ 在 ‘一个’ 前面,这不符合习惯,而且没有裨益