When there is a variable declaration inside the function body, which shares its name to a referenced identifier in default parameter expression, the function body should be wrapped into iife, otherwise the binding in default parameter scope will be shadowed by function body.
14 lines
230 B
JavaScript
14 lines
230 B
JavaScript
var x = "outside";
|
|
|
|
function outer() {
|
|
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
|
|
return x;
|
|
};
|
|
return function () {
|
|
var x = "inside";
|
|
return a();
|
|
}();
|
|
}
|
|
|
|
outer();
|