Skip to content

Instantly share code, notes, and snippets.

@ruanyf
Created January 20, 2017 07:03
Show Gist options
  • Save ruanyf/a52858ac61f11b81fedb8694a4029e97 to your computer and use it in GitHub Desktop.
Save ruanyf/a52858ac61f11b81fedb8694a4029e97 to your computer and use it in GitHub Desktop.
默认参数的作用域
// 情况一
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