Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6697] Method not defined reference error in Android Classic app using 9.3.2.GA

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDone
Resolution Date2021-06-03T10:40:45.000+0000
Affected Version/sAppcelerator Studio 4.3.0
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
Reportershishir.roy
AssigneeAbir Mukherjee
Created2021-04-27T06:24:23.000+0000
Updated2021-06-03T10:40:45.000+0000

Description

Hi Team, We have a classic app maintained for the long time. After upgrade from 8.2.1.GA to 9.3.2.GA, getting reference error while executing our app. So we have global methods in *app.js* and we are accessing from other pages without including "app. j's". But after upgrading its throws exception while app executing. Below sample code for app.js method: var sampleMethod= function(){} Same sampleMthod we are accessing in other page without including the app.js. It works well in 8.2.1.GA I have fixed the issue just including "app.js" in page. So is there any settings are available to enable the global methods. Instead of changing everyplace. Please suggest.

Comments

  1. Ewan Harris 2021-04-27

    [~shishir.roy], this is part of the documented removal of the global scope for variables/functions declared in the app.js file. Please see this blogpost for recommendations https://devblog.axway.com/mobile-apps/how-to-globally-access-variables-and-functions-in-titanium/ Also, this type of question is not really the intention of this issue tracker, I would recommend making use of [ti-slack](https://tislack.org/) in future
  2. Joshua Quick 2021-04-27

    Right, like [~eharris] said, this was an intentional breaking-change made in Titanium 9.0.0. All functions and var declared variables in the "app.js" (or "alloy.js") are no longer global. If you want them to be global, then you need to do so explicitly. For example, if you want to make the below variable and function global.
       // app.js
       var myGlobalString = "Hello World";
       function myGlobalMethod() {
       	return console.log("Global method called.");
       }
       
    ...then change the above to the below. (Note the usage of the "global" object.)
       // app.js
       global.myGlobalString = "Hello World";
       global.myGlobalMethod = function() {
       	return console.log("Global method called.");
       };
       
    You can then access the above variables globally with the "global." prefix in the rest of your code.
       // foo.js
       console.log(myGlobalString);
       myGlobalMethod();
       

JSON Source