Created
January 20, 2017 07:03
-
-
Save ruanyf/a52858ac61f11b81fedb8694a4029e97 to your computer and use it in GitHub Desktop.
默认参数的作用域
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
// 情况一 | |
let str = 'outer'; | |
function foo(x = () => str) { | |
let str = 'inner'; | |
console.log(x()); // outer | |
} | |
foo(); | |
// 情况二 | |
let str = 'outer'; | |
function foo(str, x = () => str) { | |
str = 'inner'; | |
console.log(x()); // inner | |
} | |
foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment