Somehow something feels wrong or dirty by doing this, but it seems to be more semantic than using exports or window. Is this ok?
(function(global){
var foo,bar;
foo = 'Private Var';
global.bar = 'Hello World';
})(window);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your pattern is fine. Consider this, though:
This pattern does not rely on the
"window"name, which makes it portable. (The name"root"is, of course, arbitrary.)