I have my javascript file:
foo.js
var FooNS = {
T:5,
S: FooNS.T+5, //ERROR1
doSomething : function(adder)
{
//Do Something here.
}
};
This is my other js file:
useFoo.js
$(document).ready(function()
{
FooNS.doSomething(5); //ERROR2
});
These are the two Javascript errors (via Chrome Inspector), that I get on my page which includes the js(s):
- ERROR1 -> Uncaught TypeError: Cannot read property ‘T’ of undefined (foo.js)
- ERROR2 -> Uncaught TypeError: Cannot call method ‘doSomething’ of undefined (in useFoo.js)
I am not able to figure out the reason for these errors/ the correct usage of namespaces. Any suggestions?
Tdoesn’t exist as a global variable, which is how you are trying to use it.What you are looking for is probably something akin to this:
The second error is because
FooNSis never created as an object due to the first error, thusFooNSis undefined.