Hi It is good practice to create one unique global object that wrap the functions and properties inside this object.I look up a lot of sample code and see code like this
if(!myglobalObject) mygl开发者_如何学JAVAobalObject ={};
However , this code does not work ,I got an error saying ReferenceError: myglobalObject is not defined Can anyone shed some light on why I got the error?
To avoid errors in ECMAScript 5 strict mode, you need to use var to define all variables:
if (typeof myglobalObject == "undefined") {
    var myglobalObject = {};
}
The other alternative is to assign a property to the global object:
// The following line gets you a global object in any ECMAScript
// environment, so long as it runs in the global scope. In browsers,
// you could just use window.
var globalObj = this;
if (typeof globalObj.myglobalObject == "undefined") {
    globalObj.myglobalObject = {};
}
if (typeof myglobalObject === 'undefined') var myglobalObject = {};
if (window['myglobalObject'] === undefined) window.myglobalObject = {};
If you don't want to expose your object from context you can do smth like this:
var myglobalObject = myglobalObject || {};
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论