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

Removing Reference to Top-Level Vars #43

Open
deecewan opened this issue Oct 6, 2016 · 1 comment
Open

Removing Reference to Top-Level Vars #43

deecewan opened this issue Oct 6, 2016 · 1 comment

Comments

@deecewan
Copy link

deecewan commented Oct 6, 2016

Hey,

I'm trying to get a legacy project onto ES, and I'm having a few issues.

I'm only targeting *.es6.js files, so that we can slowly move across over time. That seems to be working fine for application.js.

My problem is that there are some variables defined at the bottom of application.js, and in other files at the top level.

They are then accessed from the templates.

e.g.

// application.js
var init_browser_warning = function() {
  $buoop = {vs:{i:9,f:12,o:11,s:10,n:9}, newwindow: true, url: 'http://browsehappy.com/'}
  $buoop.ol = window.onload;
  window.onload=function(){
   try {if ($buoop.ol) $buoop.ol();}catch (e) {}
   trigger_browser_update($buoop)
  }
}

then, in the page's template

<script>
init_browser_warning();
</script>

Before installing sprockets-commoner, I would get no errors. Now, these variables are undefined. The variables are still present at the bottom of application.js (after compilation, in the browser).

It makes me very cautious to move across, because I don't know what other things will break. The application is quite large and has been written over a long time.

Any advice as to how to rectify this (or even what is causing it? I can't see anything that Commoner has added that would cause this).

@bouk
Copy link
Contributor

bouk commented Oct 13, 2016

commoner wraps everything in a function, so top-level vars aren't available. Try doing window.init_browser_warning instead

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

2 participants