Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

defer accessing a variable until available in js

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");
    }
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #defer #accessing #variable #js
ADD COMMENT
Topic
Name
9+5 =