Window object acting weird in Chrome and IE
Consider the following HTML example:
<div id="about">
<!-- content here -->
</div>
And the following script
var about = (function ($, window, document) {
"use strict";
var methods;
methods = {
init: function () {
// Do things here
}
};
return methods;
} (jQuery, window, document));
At this point, the variable aboutshould be bound to the object window.
In Firefox (3.6.17) I can write
window["about"]
And if about is not processed yet, it will return undefined, if it is, it will return the object as I expect.
However, the problem is that the same code window["about"]in Chrome and IE (7 and 8) returns the actual HTML object. In the above example, it will return the following:
<div id="about">
<!-- content here -->
</div>
Why is this happening?
Also, is there a better way to check and see if an object is accessible aboutthan using an element window? I understand that ideally I do not want to put a window object, but this is a completely different issue.
thank
Unfortunately, the only way to do this is:
function global(name) { return eval(name); }
if( global("about") )
...
Try the following: http://jsfiddle.net/PMqPv/1/