闭包的应用
// 应用:封装一段代码
let xm = (function (){
let a = 10;
let b = 20;
function add(){
return a + b
}
function sub(){
return a - b
}
return {
add,
sub
}
})()
let result1 = xm.add()
let result2 = xm.sub()
console.log(result1) // 30
console.log(result2) // -10