Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12648] TiAPI: Create a "global" variable

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsTiAPI
Labelsn/a
ReporterBryan Hughes
AssigneeUnknown
Created2013-02-08T21:38:21.000+0000
Updated2018-02-28T20:04:27.000+0000

Description

Sharing variables between modules is complex. The proper way is to use an intermediary to pass the values back and forth, but this is a lot of effort for something simple. Some platforms simply reuse the same context for all modules (this is undocumented), but that is a bad idea for both performance reasons and because it increases the chance of nasty bugs. The proper way is to have some variable in the "module" scope that allows access to the true global scope. There is plenty of precedence for this because browsers have the "window" object and node.js has the "global" object that references the "true" global scope. We should do something similar and provide a "global" object.

Comments

  1. Ivan Skugor 2013-02-12

    IMHO - sharing variables between CommonJS modules is ... not so hard. :) Community devs use "global" (so to say) module and require it where it is needed.
       //globals.js
       
       //trivial implementation
       module.exports = {};
       
       
       //module1.js
       var globals = require('globals');
       
       globals["testVar"] = "Something";
       
       
       //module2.js
       var globals = require('globals');
       
       //somewhere
       Ti.API.info(globals["testVar"]);
       
       
  2. Chris Barber 2014-03-04

    Backlog? :(

JSON Source