Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26593

Problem with variable scope in SDK 7.5.0GA

    Details

    • Type: Story
    • Status: Open
    • Priority: None
    • Resolution: Unresolved
    • Affects Version/s: Release 7.5.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Description

      Hello!
      Steps to reproduce:
      app.js

      var axwayExample = true; 
      var data = ""; // this works with 7.4.1GA
      // data = ""; // this works 7.5.0GA
       
      if (axwayExample) { 
      data = "this is global data"; 
       
      } else { 
      data = "this is login global data";
      }
      var platform = Ti.Platform.osname; 
      var Window = require('/FirstView');
      var win = new Window();
      win.open();
      

      FirstView.ja

      function FirstView() {
      	var self = Ti.UI.createWindow({
      		backgroundColor : '#ffffff'
      	});
       
      	var label = Ti.UI.createLabel({
      		color : '#000000',
      		text : 'Hello',
      		height : 'auto',
      		width : 'auto'
      	});
      	self.add(label);
       
      	//Add behavior for UI
      	label.addEventListener('click', function(e) {
      		alert(data);
      	});
       
      	return self;
      }
      module.exports = FirstView;
      
      

      Discription:
      In 7.4.1 and earlier, any variables defined with the var keyword in app.js were considered as
      global variables. But it's not working in 7.5.0.GA
      You can see that to get global variables to work on 7.5.0, the data variable
      needs to be defined without the var keyword.

      The main difference in code is that I define the data variable, and set
      it to an empty string. Then with a if statement, I modify the data
      variable, but it does not get passed to the alert function in 7.5.0GA
      unless I do the change as indicated.

      Test Environment:

      Operating System
        Name                        = Microsoft Windows 10 Pro
        Version                     = 10.0.17134
        Architecture                = 32bit
        # CPUs                      = 4
        Memory                      = 17091956736
      Node.js
        Node.js Version             = 8.9.1
        npm Version                 = 5.5.1
      Titanium CLI
        CLI Version                 = 5.1.1
      Titanium SDK
        SDK Version                 = 7.5.0.GA
      

      Thanks

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                aislam Aminul Islam
              • Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-6728
                    Sync status:
                    PENDING
                    Last received:
                    Last sent:

                    Git Source Code