Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1259] Alloy: The code in alloy.js should be wrapped by app.js to protect global scope

GitHub Issuen/a
TypeImprovement
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sAlloy 1.5.1, Alloy 1.7.0
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterFokke Zandbergen
AssigneeFeon Sua Xin Miao
Created2015-03-30T17:46:01.000+0000
Updated2015-07-09T14:48:33.000+0000

Description

The code a developer adds to app/alloy.js will simply be injected into the generated Resources/<os>/app.js file as can be seen in the [template](https://github.com/appcelerator/alloy/blob/master/Alloy/template/app.js). Unlike the CommonJS modules that make up the rest of an Alloy app, all variables in this file will be part of the global scope. We could enforce a best practice to not pollute the global scope by wrapping the imported code in a self-executing function like this:
(function(exports) {
	
__MAPMARKER_ALLOY_JS__
	
})(this);
This way, the developer can still force to set a global by using exports.foo = "bar"; just like they export variables in controllers.

Warning

This **will** break apps that depend on globals set in alloy.js, other then those using Alloy.Globals.

Comments

  1. Fokke Zandbergen 2015-03-30

    PR on master: https://github.com/appcelerator/alloy/pull/675

JSON Source