mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
代码片段有误
http://es6.ruanyifeng.com/#docs/decorator#为什么修饰器不能用于函数?这一节的第二个代码片段,函数声明和变量声明都会提升,但是函数声明先于变量声明。
This commit is contained in:
parent
6c0a3f180e
commit
b9a4aa449d
@ -251,13 +251,13 @@ function foo() {
|
||||
上面的代码,意图是执行后`counter`等于1,但是实际上结果是`counter`等于0。因为函数提升,使得实际执行的代码是下面这样。
|
||||
|
||||
```javascript
|
||||
var counter;
|
||||
var add;
|
||||
|
||||
@add
|
||||
function foo() {
|
||||
}
|
||||
|
||||
var counter;
|
||||
var add;
|
||||
|
||||
counter = 0;
|
||||
|
||||
add = function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user