Although I don't understand the details of what you're doing, it seems that your basic problem is that in JavaScript you can't reference a non-existent data item (e.g. pass it to an 'exists()' function) without triggering a runtime error. One workaround you might experiment with is to preface the object name with 'window.'. Provided that you're working in a browser environment, global variables are actually properties of the global 'window' object. Referencing a non-existent property of an object merely returns 'undefined' and doesn't generate a runtime error. The following global code (not inside a function) illustrates this point:
Code:
var x = 5;
/* displays 5: */
alert (x);
/* also displays 5: */
alert (window.x);
/* y has NOT been declared, i.e. it doesn't exist: */
/* just displays "undefined": */
alert (window.y);
/* causes a runtime error: */
alert (y);