Jump to content
Sign in to follow this  
warleyalex

Avoid pollute the global namespace

Recommended Posts

At the default project options, when you left unchecked the option:

[ ] embedd JS into HTML file

 

it will generate in the main index.html this:

<script src="main.js"></script>
All javaScript declarations outside of a function are in the global scope. Defining things in the global namespace is to be avoided.

I'll use a differente pattern, a simple closure around the main.js generated code

 

(function() { /* the main.js code */})();

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×