function test() {
var a = 1
function plus() {
a++
console.log(a);
}
return plus
}
var plus = test()
plus()//2
plus()//3
plus()//4
window 和 return 都可以把 a 返回全局
function test() {
window.a = 123
var b = 58
}
test()
console.log(a);//123
console.log(b);//b is not defined
function test() {
return a = 123
var b = 58
}
test()
console.log(a);//123
console.log(b);//b is not defined
var add = (function () {
var a = 1
function add() {
a++;
console.log(a);
}
return add;
})()
add()//2
add()//3