Reputation: 13
example of js file that will be parsed during loading:
var Test = {
someProp: Utils.getProp()
}
var Utils = {
myAttr: "",
getProp: function() {
alert("Test");
}
}
The error that I'm getting during page loading is
"TypeError: Utils is undefined"
As far as I understand js interpreter is executing script during page load and in such case the error is occuring. The question here: is it real to load the page and to avoid the script execution? or how can I avoid the error?
Upvotes: 0
Views: 65
Reputation: 324740
Since Test
depends on Utils
, Utils
must be defined first.
var Utils = {
myAttr: "",
getProp: function() {
alert("Test");
}
}
var Test = {
someProp: Utils.getProp()
}
Upvotes: 2