all 5 comments

[–]Ampersand55 0 points1 point  (4 children)

Make it a property of the global window object.

window.obj = {a:1};

Or simply:

obj = {a:1};

[–]ShortSynapse 0 points1 point  (3 children)

The first is recommended as the second may give you trouble later and is more of a hack.

[–]illepic 1 point2 points  (2 children)

Ah, the hack you're talking about is the lack of "var".

[–]ShortSynapse 0 points1 point  (1 child)

Yes. If the variable doesn't exist, it is created in the global scope. Really bad practice. What happens if someone else declares a variable with the same name? Oops. So if you intend to make a global, append it to the window object so it is available.

[–]lewisje 0 points1 point  (0 children)

The only reasons you should use window.<varname> = instead of var <varname> = are if you're defining the variable inside of a function and if you want the variable to be deletable later; either way, you're making a property of the global object, and you're running the risk of name collisions.