A problem was encountered in the recent project where the Window object was rendered when the page was loaded, an object obj was added to the window during rendering, a file was loaded, and an attribute para was added to obj, but the process was asynchronous.
You then need to detect if the window has an Obj object, and if the Obj object has the Para property. Because it is asynchronous. When performing this operation, it may not render to para, and if is required. else.. Perform another set of operations.
When you encounter a problem, how can I tell if the window object has an Obj object and if the Obj object has a Para property?
The previous use of the ' obj ' in window judgment. But to take my big say this is not very good for the system performance, I hope I can be implemented in another way.
After lookup, locate the hasOwnProperty operation using Window.hasownproperty (' obj ') && window.obj. hasOwnProperty (' Para '), which was judged.
But there is a problem with this approach: you can only judge if your own property exists, and you cannot judge an inherited property.
Use undefined judgment: window.obj!== undefined;
You can use this method to determine your own properties and inheritance properties, but when the obj value is undefined, it fails.
Use conditional statements to directly determine if (!! Window.obj.para).
But using this method, if the property value is Undefined,null, "", 0, time, return false
Reference: http://www.3lian.com/edu/2013/05-20/70754.html
Attribute detection in a JS object