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

Scope, IIFEs etc #24

Open
des-des opened this issue Jun 27, 2017 · 1 comment
Open

Scope, IIFEs etc #24

des-des opened this issue Jun 27, 2017 · 1 comment
Assignees

Comments

@des-des
Copy link
Collaborator

des-des commented Jun 27, 2017

Okay, this came up in a pull so I thought I would drop my thought in an issue.

The top level scope in a js file is global in the browser, You should not be writing code here as you will accidentally declare variables in global scope (very bad).

I see 2 ways of sharing stuiff between files

1: Declare only one global variable. call it echo.

The

// some_file.js
(() => {
  var self = {}
  var x = 2; // private

  self.y = 3 // will be exposed

  // lots more stuff

  echo.someFile = self;
}());

You can also use $document.ready(() => {}) or something from jquery

2:
Write your code as if in node (module.exports, require), then use browserify

@des-des des-des assigned joeylouise, ghost and pbywater Jun 27, 2017
@ghost
Copy link

ghost commented Jun 28, 2017

Thanks for this Eoin!

ghost pushed a commit that referenced this issue Jun 28, 2017
before, we were declaring global variables.
I have changed this now so that any variables that we need across functions are declared in an iife and saved to the one GV echo.
relates #24
@des-des des-des mentioned this issue Jun 28, 2017
des-des added a commit that referenced this issue Jul 3, 2017
related #24

Conflicts:
	public/scripts/d3/d3.js
	public/scripts/d3/setup.js
	public/scripts/helpers/helpers.js
des-des added a commit that referenced this issue Jul 3, 2017
des-des added a commit that referenced this issue Jul 3, 2017
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