How do I see if a certain object has been loaded, and if not, how can it be loaded, like the following?
if (!isObjectLoaded(someVar)) {
someVar= loadObject();
}
If it is an object then you should just be able to check to see if it is null or undefined and then load it if it is.
if (myObject === null || myObject === undefined) {
myObject = loadObject();
}
Using the typeof function is also an option as it returns the type of the object provided. However, it will return null or undefined if the object has not been loaded so it might boil down a bit to personal preference in regards to readability.
if(typeof(o) != 'object') o = loadObject();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With