📜  推迟访问变量,直到在 js 中可用 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:18.788000             🧑  作者: Mango

代码示例1
let obj = encapsulatedObject || window;
Object.defineProperty(obj, "myVar", {
    configurable: true,
    set(v){
        Object.defineProperty(obj, "myVar", {
            configurable: true, enumerable: true, writable: true, value: v });
        console.log("window.myVar is defined");
    }
});