App type: Mobile will run on Android&ios.
As u know, using "require" is recommended by Titanium. Can I use a shared js file which will be required by every other files?
Etc. I write some common functions and variables in common.js, and "require('common')" in other js file, to make the common functions and variables to be global vars.
if it's ok, there is any problems with memory? Or the common functions and variable maybe lost at some time. if not, any advice please.
Sorry to my poor english, but please give some suggestions. I think not only me, many developers want to know about this.
2 Answers
Accepted Answer
This is exactly the reason for commonJS. You can require it as often as you need, Ti will cache the Module, so you get a Kind of singleton.
You will not be able to maintain global state. The 'global' object you get from requiring a file is a new one each time. Somebody please correct me if I am wrong.
My solution is to pass my global object as a parameter to required files:
var thing = require('some_other_thing).(GlobalVar, opts)
Your Answer
This question has been locked and cannot accept new answers.