[TIMOB-8082] iOS: Global variables are accessible in CommonJS module's scope
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-01-28T23:44:30.000+0000 |
Affected Version/s | Release 2.0.0, Release 1.8.2, Release 3.1.0 |
Fix Version/s | Release 3.2.0 |
Components | iOS |
Labels | qe-closed-3.2.2 |
Reporter | Sandeep Bhimavarapu |
Assignee | Ingo Muschenetz |
Created | 2012-03-19T12:41:05.000+0000 |
Updated | 2014-03-11T07:21:41.000+0000 |
Description
Globals can be brought in to the module's scope on iOS. Please see the following code.
*SAMPLE CODE*
{noformat}
app.js
================================
var App = {};
var myModule = require('myModule');
new myModule();
myModule.js
================================
App.MyModule = function() {
return Ti.UI.createWindow({backgroundColor:'red'}).open();
};
module.exports = App.MyModule;
{noformat}
*STEPS TO REPRODUCE*
1. Create a Titanium Mobile project and copy the following code into app.js and myModule.js
2. Run the project and a blank window with red background color will be seen
*OBSERVED BEHAVIOR*
1. Window with red background color is seen.
*EXPECTED BEHAVIOR*
1. A runtime error indicating the use of global object.
*OTHER OBSERVATIONS*
1. On Android, a runtime error is noticed with the message "Uncaught ReferenceError: App is not defined"
Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
Verified the fix, hence closing the issue. Environment used: Device : iPod touch 2 , iOS version: 7.1 SDK: 3.2.3.v20140310185916 CLI version : 3.2.1 OS : MAC OSX 10.9 Alloy: 1.3.1 ACS: 1.0.14 npm:1.3.2 Appcelerator Studio, build: 3.2.2.201403061827 titanium-code-processor: 1.1.0 XCode : 5.1 Beta 5