PROBLEM DESCRIPTION
Customer refactored his app to use the require function instead of Ti.include. But I detect an issue with the require feature. My instanceof checks do no longer work. It's a bit strange and took me a long time to break it down.
STEPS TO REPRODUCE
1. Create new mobile project
2. Add app.js listed below
var win = Ti.UI.createWindow();
win.open();
function callback (myarray) {
if ((myarray instanceof Array)) {
alert('myarray is instance of array');
} else {
alert('myarray is NOT instance of array');
}
};
var caller = require('caller');
var call = new caller();
call.setCallback(callback);
call.start();
3. add a file caller.js with this:
function caller () {
}
caller.prototype.setCallback = function (callback) {
this.callback = callback;
};
caller.prototype.start = function () {
this.callback.apply({}, [[]]);
};
module.exports = caller;
EXTRA INFO
In iOS is working fine. Screenshots attached.
There is definitely something strange going on here. The issue is not related to "apply" function, regular function call ("this.callback([])") also suffers from same problem. I tried to see "myarray" variable contains but debug information does not show.
It seems like array's value is lost somewhere.
Same happens for example with a
(myobject instanceof Object)
check. Doesn't work.I can't reproduce the problem, it works fine with SDK 3.1.0.
Closing ticket as the issue cannot be reproduced.