1-js/06-advanced-functions/04-var#80
Merged
leviding merged 4 commits intojavascript-tutorial:zh-hansfrom May 5, 2018
Merged
Conversation
Contributor
Author
|
@leviding 翻译完成~ |
Contributor
|
@leviding 校对认领 |
Starriers
reviewed
May 5, 2018
Contributor
Starriers
left a comment
There was a problem hiding this comment.
@NoName4Me @leviding 校对完成
| # 旧时的 "var" | ||
|
|
||
| In the very first chapter about [variables](info:variables), we mentioned three ways of variable declaration: | ||
| 在前面的[变量](info:variables)那一章,我们讲到了变量声明的三种方式: |
| 如果我们在第二行使用 `let test`,那么 `alert` 就无法访问到它。因为 `var` 忽略块级代码,所以我们得到了一个全局的 `test`。 | ||
|
|
||
| The same thing for loops: `var` cannot be block- or loop-local: | ||
| 循环也是这样,`var` 无法成为块级或循环局部: |
|
|
||
| *!* | ||
| alert(i); // 10, "i" is visible after loop, it's a global variable | ||
| alert(i); // 10, "i" 在循环结束后仍然可见,它是一个全局变量 |
| `var` 声明在函数开始时处理(或者全局声明之于脚本开始)。 | ||
|
|
||
| In other words, `var` variables are defined from the beginning of the function, no matter where the definition is (assuming that the definition is not in the nested function). | ||
| 换言之,`var` 变量在函数开头被定义,无论定义在什么地方(假设定义不在嵌套函数里)。 |
| ``` | ||
|
|
||
| ...Is technically the same as this (moved `var phrase` above): | ||
| ...它完全等同于这个(`var phrase` 上提): |
Contributor
Author
|
@Starriers 已修改,谢谢~ @leviding |
leviding
approved these changes
May 5, 2018
Member
|
很赞很标准 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
resolve #71