[AC-4834] Defining var in Alloy.js causes global scope
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Invalid |
Resolution Date | 2017-03-03T14:11:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | alloy.js, scope, variables |
Reporter | Creative |
Assignee | Shak Hossain |
Created | 2017-03-03T09:58:01.000+0000 |
Updated | 2017-03-03T14:11:56.000+0000 |
Description
Defining a *var* in alloy.js actually creates a "global" variable since the context is the app itself. One would expect to have any local variable here go out of scope.
// File: app/alloy.js
var mytestvar = 'foobar';
Next, open any controller or common.js module, and simply retrieve the variable using *console.log(mytestvar);*. It will exist forever during the app's runtime.
I know one solution is to simply put alloy.js in a *(function(){})()* wrapper but the current implementation seems wrong by design.
This is made by design. The alloy.js is meant to be global if needed (although not recommended). People usually store global modules instances like Ti.Map there.