I know there are a lot of “how do I avoid this warning” questions, but it looks like mine is the first specific to JavaScript. In this case, I want to reference the thing I’m initializing inside its own declaration, like so:
var foo = new Foo({
bar: new Bar({
x: function(){
doStuff(foo);
}
});
});
(If this looks familiar, maybe you’ve used ExtJS before — this is how most of their stuff is built.)
When I call foo.bar.x(), I want to point back to the Foo (foo) that owns the Bar (bar) that’s calling the function (x). This works, but my Eclipse warns me that “foo may not have been initialized”, referencing the call to doStuff(); — because, when the engine first sees the line, we haven’t finished defining foo yet. Of course, x() can’t be called unless foo is constructed successfully, but my style checker apparently hasn’t figured that out.
So I’m at a loss for how to deal with this. Should I ignore the warning? Is there a way to mark it as such, so I don’t get a warning anymore? Am I doing this wrong? Should I pass my reference in a different manner?
Eclipse is right. Again if you want a better analysis system consider using WebStorm 3.0 or Visual Studio 11 as your JS IDE.