Ti.include

You must Login before you can answer or comment on any questions.

What is the use of Ti.include can any one explain with sample code

3 Answers

other.js

function Blah() {
   alert("This is another file!");
}
app.js
Ti.include('other.js');
var win = Ti.UI.currentWindow;
var button = Ti.UI.createButton({
   title:'Click me for coolness',
   left:'auto',
   top:'auto',
   width:33,
   height:33
});
 
win.add(button);
 
button.addEventListener('click', Blah);
Pretty much exact same as a regular JavaScript Include or PHP Include.

The easiest way to understand Ti.include() is to simple treat this as a simple copy/paste of your code and nothing more!!!

For different behavior you should check CommonJS modules, i.e. the 'require()'

In your example,

Ti.include('other.js');
var win = Ti.UI.currentWindow;
var button = Ti.UI.createButton({
   title:'Click me for coolness',
   left:'auto',
   top:'auto',
   width:33,
   height:33
});
 
win.add(button);
 
button.addEventListener('click', Blah);
is identical to

function Blah() {
   alert("This is another file!");
}
 
var win = Ti.UI.currentWindow;
var button = Ti.UI.createButton({
   title:'Click me for coolness',
   left:'auto',
   top:'auto',
   width:33,
   height:33
});
 
win.add(button);
 
button.addEventListener('click', Blah);

Your Answer

Think you can help? Login to answer this question!