Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5496] Have an include_once function

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2011-10-11T19:13:19.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTiAPI
Labelslook1
ReporterShauna
AssigneeDon Thorp
Created2011-10-10T11:27:05.000+0000
Updated2017-03-21T21:05:31.000+0000

Description

An include_once function, such as what can be found in PHP would be extraordinarily useful on the mobile side to help prevent unnecessary duplicate inclusion in the same context. A good example is with the use of the date.js library. Including it twice in the same context results in recursion errors whenever the library's .toString() function is used (because it stores the prototype .toString in a new variable and replaces it with its own, the second include makes it replace the prototype backup with the custom function). Having the ability to use Ti.include_once() to prevent a file from being loaded twice would keep such an error from happening to begin with.

Comments

  1. Paul Dowsett 2011-10-11

    Just to be bear in mind, this is a very simple function to create yourself in javascript, so I doubt this will be a high priority. Having said that, I will move it to the main project for the core team's consideration.
  2. Paul Dowsett 2011-10-11

    Shauna btw, require() does this, or you can implement include_once as a file read and eval. Please open a Q&A question if you need more help with this. Marking resolved.
  3. Shauna 2011-10-12

    Paul That's good to know. Perhaps it should be more prominent in the docs? The only reference I can find to require() is one instance in KS that doesn't really say much (and, in fact, seems to suggest that it's only for CommonJS stuff, which may not be useful for files that don't follow the commonJS standard, and has a known issue for not working on distribution builds - http://developer.appcelerator.com/question/125313/error-using-require-and-packaging-app-android).
  4. Lee Morris 2017-03-21

    Closing ticket as invalid.

JSON Source