Hi guys.
I'm putting together a JavaScript module and mostly things work as expected. I have a simple test, which features two views. On a button click, the first view creates a new instance of the second view and adds it as a child. Both views use my custom JS module. But after 2 or 3 times of creating the child view, my module's function's aren't accessible; I get 'undefined' is not a function. Here are some code samples:
[Slideshow.js - this is where the code fails]
function slideshow(container) { var iron = require("com.jasonsultana.IronForge"); Ti.API.debug("IronForge: " + JSON.stringify(iron)); iron.hello(); return Ti.UI.createView({ top: 0, left: 0, height: 0, width: 0 }); }[FirstView.js]
function FirstView() { var iron = require("com.jasonsultana.IronForge"); var slideshow = require("ui/common/slideshow"); var v = Ti.UI.createView({ top: 0, height: '100%', left: 0, width: '100%', backgroundColor: 'white' }); v.addEventListener('click', function(e){ this.add(new slideshow(this)); }); return v; }[Slideshow.js]
var IronForge = { hello: function() { Ti.API.debug("Hello World"); } }; module.exports = IronForge;For the record, I've tried defining this as
IronForge.hello = function(){}, but it produces the same result. I didn't want to use the prototype, since I wanted my methods to be static. The code runs fine for the first 2-3 times, then after the 4th or so instance of Slideshow, it fails.
Any ideas?