立即执行函数 —— 隐藏私有成员

const module = (function() {
    let a = 25;
    const m1 = () => {
        console.log(a);
   }
    return {
        foo1: m1,
    }
})()

Chrome测试:

module.foo1()
// 25

猜你喜欢

转载自blog.csdn.net/Nana_9457/article/details/82882533