This technique of "private state" in recent years has become increasingly idiomatic. Personally, I found that this strangely limits the attempt to quickly debug something from the console or override the behavior in a third-party library. This is one of the few times that I think, “Damn it, why I can't do this with the language.” I used this error in Firefox 2 for a good effect when I really need to quickly debug a "private variable".
I would be interested to know when others use this idiom or when they avoid it. (@bobince, I look at you).
Anyway, @bobince pretty much answered your question (nutshell: No, you cannot access the canvasDiv variable from the area you are in).
However, there is one thing you can do is the trade-off between hacking or editing a third-party library (I always go for hacking;): you can enlarge the object to keep the link that you know you need later.
Hack 1 : if you manage object instances yourself:
var canvas = document.getElementById('canvas'); var gr = new jsGraphics(canvas); gr._canvasDiv = canvas;
If the library supports some concept similar to a destructor (it is activated when a page is unloaded or something like that), be sure to remove or delete your property there to avoid memory leaks in IE:
delete gr._canvasDiv;
OR Hack 2 : Overwrite the constructor immediately after turning on the library:
// run after including the library, and before // any code that instantiates jsGraphics objects jsGraphics = (function(fn) { return function(canvas) { this._canvasDiv = canvas; return fn.apply(this, arguments) } }(jsGraphics))
Then select the item (now public) as gr._canvasDiv . This is the same remark about deleting it on page unloading.
source share