function createIncrement() {
let count = 0
function increment() {
count++
console.log(count)
}
let message = count
function log() {
console.log('message: ', message)
console.log('count: ', count)
}
return [increment, log]
}
const [increment, log] = createIncrement()
increment()
increment()
increment()
log()
// 输出
1
2
3
message: 0
count: 3
var t = function() {
var n = 99
var t2 = function() {
n++
console.log(n)
}
return t2
}
var a1 = t()
var a2 = t()
a1()
a2()
// 输出
100
100
var nAdd
var t = function() {
var n = 99
nAdd = function() {
n++
}
var t2 = function() {
console.log(n)
}
return t2
}
var a1 = t()
var a2 = t()
nAdd()
a1()
a2()
// 输出
99
100