闭包解决命名空间污染问题
var init = (function () { var name = "zhangsan", age = 12, sex = "male", _class = 2019 function sayName() { console.log(name); } function sayAge() { console.log(age); } return function () { sayName(); sayAge(); } }()) init();
闭包解决命名空间污染问题
var init = (function () { var name = "zhangsan", age = 12, sex = "male", _class = 2019 function sayName() { console.log(name); } function sayAge() { console.log(age); } return function () { sayName(); sayAge(); } }()) init();