[TIMOB-5496] Have an include_once function
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-10-11T19:13:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | TiAPI |
Labels | look1 |
Reporter | Shauna |
Assignee | Don Thorp |
Created | 2011-10-10T11:27:05.000+0000 |
Updated | 2017-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.
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.
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.
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).
Closing ticket as invalid.