Search code examples
javascriptappcelerator-mobile

Defining JavaScript classes in Appcelerator Titanium


I am trying to use Appcelerator Titanium to build a mobile app. This app will be large and to make it manageable, I want to use JavaScript classes. Currently, I have a JavaScript class that is defined as follows:

function Item()
{
  this.ID = 0;

  this.initialize = function(id) {
    this.ID = 1;
  }

  this.Submit = function(submitHandle) {
    submitHandle();
  };
}

I then invoke this class using the following:

alert("building Item");
var i = new Item();
alert("initializing Item");
i.initialize(1);
alert("submitting");
i.Submit(itemSubmitted);

function itemSubmitted() {
  alert("tada!");
}

The alert message that says "buidling item" appears. However, "initializing item" never shows. In addition, my item is never submitted. I do not get an error. What am I doing wrong?


Solution

  • Try this: Instead of using this.ID = 0 in your Item class, try using just ID = 0;