Appcelerator / Titanium - Are Javascript variables polluting the global scope in controller files?

StackOverflow https://stackoverflow.com/questions/21482438

Question

I'm new to Appcelerator and Titianium Alloy, and I wandering how the global scope works in the controller Javascript files.

It is still best practice to attach all of your variables to a single global object within these files? In a lot of tutorials it seems that they are just declaring variables with quite common names right in the file with no closure of the scope.

Était-ce utile?

La solution

Put your global variables and functions in your app/alloy.js:

 Alloy.Globals.myModule = require("myModule");

 Alloy.Globals.myFunction = function(e){
     // your logic function
 };
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top