【顶层window隔离】
Demo 利用 window 这个内置对象
{
function f1(){
console.log("this is 4.3.js f1");
}
let f3 = function(){
console.log("this is 4.3.js f3");
}
window.scope3 = {f1,f3};
// 很巧妙地利用了顶层对象的属性来隔离作用域
}
(function (window) {
function f1() {
console.log("this is 4.2.js f1");
}
window.scope2 = { f1 };
})(window);

浙公网安备 33010602011771号