问题
I'm pulling my hair out over IE9/8; I'm trying to use mOxie, but it's showing up as undefined
, even though it's very clearly defined.
when, from another file, I log mOxie
to the console, it logs it perfectly fine in Chrome/IE10+, but firing the same script in IE9/8 logs undefined
.
However, in IE9/8, when I type 'mOxie' in the console directly, it correctly logs the object.
http://jsfiddle.net/vxyayxy8/ -- Run in IE10 mode, and you'll see that it loads an object. Run in IE9 mode, and you'll see that it logs undefined
Why is it that in IE9/8, when logging from a file (that's included after mOxie), it's undefined
, but is defined in IE9/8 when using the console directly?
Keep in mind that it's defined in Chrome and IE10+.
To test the theory of my answer below, in IE11, but in IE9 document mode, do console.log({})
-- I get undefined
, which fits the question and the answer. Can you reproduce this?
回答1:
The answer below is still legitimate, but apparently it was due to an IE bug that I've now been assured has been fixed, so I'm installing updates and hoping for the best. Thanks for the help, guys.
I've discovered that doing console.log
in IE8/9 document mode (yes, the devtools are open) results in undefined
.
Why they log an object as undefined is beyond me, but the fix is to use console.dir
which results in the correct logging of an object to the console.
mOxie
was never undefined
, it was just being logged as such, through IE's bizarre implementation of the console.
Though I am getting claims that the issue cannot be reproduced, I can still get the same results,e very time I test it. http://jsfiddle.net/vxyayxy8/1/ -- This shows how log returns undefined, vs dir which returns the object.
来源:https://stackoverflow.com/questions/28283245/moxie-is-undefined-yet-very-clearly-defined