Search code examples
iphoneiostitaniumappceleratortitanium-mobile

Titanium - Create custom function, calling the function and passing arguments


I am an iPhone developer and a beginner in using Titanium studio. I started to learn Titanium few days back and worked on some samples which uses view, navgroup, images, etc. I'd like to step advance. I can not find samples to create a custom function, calling a function in Google. So, someone here guide to how to create a simple function, calling a function and sample for passing arguments. Thanks in advance.


Solution

  • It's just JavaScript, so use it like JavaScript like below:

    Example 1:

    function myFunction(arg1,arg2){
       // do stuff here
    }
    

    Example 2:

    var myFunction = function(arg1,arg2){
        // do stuff here
    }
    

    Calling function:

    myFunction(value1,value2);
    

    Memory wise it is best to do something like this:

    var app = {};
    app.myFunction = function(arg1,arg2) {}