So I was reading this question here: How to load another js file on a button click in titanium
And there are two different ways to open windows in titanium. I was wondering if there are any major performance differences or advantages of each way of opening the window? I have been looking at the documentation here:
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.Window
Also I am not using Alloy.
Anyone know if there are any advantages of using each of the methods? Code snippets below.
Method 1
var win = Ti.UI.createWindow({
backgroundColor : 'white',
url : 'home.js' //Path to your js file
});
win.open();
home.js
var myWin = Ti.UI.currentWindow;
//You can add your controls here and do your stuff.
// Note that never try to open myWin in this page since you've already opened this window
Method 2
//In your current page
loginbutton.addEventListener('click', function(e) {
var Home = require('/ui/common/Home');
var homePage = new Home();
homePage.open();
});
Home.js
function Home() {
var self = Ti.UI.createWindow({
layout : 'vertical',
backgroundColor:'white'
});
//Do your stuff here
//Add other controls here
return self;
}
module.exports = Home;
Method 1 is defunct. Don't use it. Only use Method2 which is the CommonJS way.
Please see the CommonJS best practises documentation: