(I am using pseudo-code)
I have a series of ASP.NET custom controls. Each one involves a lot of javascript, so they have corresponding .js files. They inject a line such as 'var this.clientid = new jsobject();' so every control has a javascript object on the page with the same ID as itself.
This works fine, except that some controls rely on others. For example, a CatFlap object needs to know about CatHouse. So in its constructor, it will take in the CatFlap object, a bit like this:
page.inject("var " + this.ClientID + " = new CatFlap(" + CatHouse.ClientID + ");";
however in the constructor for CatFlap, CatHouse is undefined if on the page, the 2 custom controls are in the opposite order, eg. the comes before because it hasn't constructed the item yet.
One solution is to put the declaration into document.ready(), but this fails because my control system is slightly more complicated than above, with other dependancies such as CatFlapSwitch depending on CatFlap and thus both constructors would go into document.ready() and the problem would manifest itself again.
There are many suites of tools out there that have several custom controls, does anyone know how they manage to solve this issue?
An example of the problem: http://jsfiddle.net/tckuM/
If you switch the two object declaration lines around, you get an error, I am wondering how to mitigate that.