Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global variables #1

Closed
jsvoboda opened this issue Jan 16, 2015 · 4 comments
Closed

Global variables #1

jsvoboda opened this issue Jan 16, 2015 · 4 comments

Comments

@jsvoboda
Copy link

Hi,
as a javascript newb I was kind of trying to copy the structure of your game, but realized that you are extensively using global variables.

For example:

Ball.Game = function(game) {
    keys = null;
    ball = null;
    walls = null;
        ...
};

Would you mind explaining why?

Thank you,
Jaromír

@sombriks
Copy link

He's using Ball as namespace.

Game is receiving the constructor function. It's acting as class.


Enviado do Mailbox

On Fri, Jan 16, 2015 at 8:57 AM, jsvoboda [email protected]
wrote:

Hi,
as a javascript newb I was kind of trying to copy the structure of your game, but realized that you are extensively using global variables.
For example:

Ball.Game = function(game) {
  keys = null;
  ball = null;
  walls = null;
        ...
};

Would you mind explaining why?
Thank you,

Jaromír

Reply to this email directly or view it on GitHub:
#1

@jsvoboda
Copy link
Author

Yea, I get that, but implicitly declared variables (i.e. without 'var' keyword) are global no matter where they are declared. At least it looks that way, try running the following (in console for example):

Ball = {};
Ball.Game = function(game) {
    some_variable = "imho global";
};
var game = new Ball.Game();
some_variable

@end3r
Copy link
Member

end3r commented Jan 18, 2015

The demo game was created at a doc sprint during weekend a few months ago and was just a proof of concept, but I never had the chance to finish it. I'll try to rewrite it as it should be, with all the good practices, and describe everything in detail in the related article.

@jsvoboda
Copy link
Author

Ok, thank you, I was just wondering whether there's something I am missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants