Monday 15 February 2010

backbone.js - Backbone.Events context issue in Appcelerator Titanium -


I have a Custom Library in my Titanium Mobile (3.1.0 GA SDK) project that looks like this:

  // lib / MyObject.js function MyObject {var self = this; _. Expansion (self, backbone.events); This.trigger ('myEvent'); } Module.exports = MyObject;   

In the second part of my application, I create globally available classes:

  Alloy.Globals.MyObject = require ('MyObject') ;   

And in the controller, I instantiate it:

  myObj = new Alloy.Globals.MyObject ();   

The object is passed in a while, until an event listener is added to the end:

  // Another controller MyObj.on ('myEvent' Unfortunately, the log command is never called.If I add an event listener inside the MyObject function, it works. Okay but it will not work when the object is out Called from.  

I would just assume that there is a bug, or the object is not Except for reference rather than context, I change the class definition for the following:

  // lib / MyObject.js function MyObject {var self = this; _ Extend (self, Backbone.Events); var old_on = at this; this.on = function (a, b, c) {back old_on call (self, a, b, c);} this.trigger ('myEvent' );} Module.exports = MyObject;   

... everything works. Either way the function is not finding the correct reference, but for me Why do not i know my life Has the insight into Ha?

Hmmm, 3.1.1 GADA SDK version updated. There should be a bug in titanium.

No comments:

Post a Comment