Those. 6 can't find javascript definitions
I have a javascript file a.js, its content sometimes looks like
window.model={};
model.init=(
function(){return "something"}
)();
in my html files, I have something like this:
<script type="text/javascript" src="path/to/a.js"></script>
<script type="text/javascript">
$(document).ready(function() {
model.init();
});
</script>
in chrome, firefox and ie8 works. but in ie6 or ie7 it won't be modeled like that.
I do not know why. can someone help me.
thank!
i will put a warning
in html:
<script type="text/javascript" src="path/to/a.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert("ie6");
model.init();
});
</script>
in js
alert("ie7");
window.model={};
model.init=(
function(){return "something"}
)();
first prints "ie6" but "ie7" never prints
The reference model is the same as you declare it, as a property on window
.
window.model.init=(function(){return "something"})();
$(document).ready(function() {
window.model.init();
});
Or you could do the opposite and declare it a global variable.
var model={};
This could be caused by a different order of execution or some sort of "hoisting" problem.
Try to initialize the model with "var model = {}". Then try flushing the data to the log to check the execution order. IE has tools for using console.log, or you can try firebug lite.