Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-693] iOS: Ti.include in functions

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2016-08-19T16:32:50.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sn/a
ComponentsTiAPI
Labelscore
Reporterwallneradam
AssigneeIngo Muschenetz
Created2011-04-15T02:34:37.000+0000
Updated2017-03-20T17:53:11.000+0000

Description

If I try to include a JS in a function with Ti.include, I can't access the local scope of the function from the included js. In the API documentation you wrote: "one or more filenames to include as if the Javascript code was written in place." In this way it is not true. Example:
var win1 = Titanium.UI.createWindow({  
    title:'Window 1',
    backgroundColor:'white',
    fullscreen:false
});

var globalv = 1;

function f1(){
  var v = 2;
  Ti.include('t2.js');
}

f1();

win1.open();
Ti.API.info("output of globalv is: " + globalv); // this outputs 1, as expected
Ti.API.info("output of v is: " + v); // this throws undefined exception, rather than the expected 2

Comments

  1. Stephen Tramer 2011-04-15

    Unlikely include scenario, but should be investigated. Probably has to do with JS context scope. At best, a documentation change.

  2. Paul Dowsett 2011-05-16

  3. Junaid Younus 2012-08-13

    Still able to reproduce this issue with the iOS simulator, TiSDK 2.2.0v20120810194112, TiStudio 2.1.1.201207271312.
  4. Chris Barber 2016-08-19

    ti.include() is deprecated since Titanium SDK 3.3.0 in favor of require().
  5. Lee Morris 2017-03-20

    Closing ticket as ti.include() has been deprecated since Titanium SDK 3.3.0.

JSON Source