Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7258] Android - Android does not detect an array as an instanceof Array

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-03-25T17:11:00.000+0000
Affected Version/sRelease 1.8.0.1, Release 2.0.0
Fix Version/sn/a
ComponentsAndroid
Labelsexalture
ReporterMauro Parra-Miranda
AssigneeSunila
Created2012-01-17T10:54:19.000+0000
Updated2017-03-21T21:29:50.000+0000

Description

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.

Attachments

FileDateSize
Screen Shot 2012-01-17 at 10.07.03 AM.png2012-01-17T10:54:39.000+000056407
Screen Shot 2012-01-17 at 10.33.09 AM.png2012-01-17T10:54:39.000+000037327

Comments

  1. Ivan Skugor 2012-01-19

    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.
       function callback (myarray) {
           Ti.API.debug(myarray); //doesn't print anything
           Ti.API.debug(Object.prototype.toString.call(myarray)); //prints [object Array], that's OK
           if ((myarray instanceof Array)) {
               alert('myarray is instance of array');
           } else {
               alert('myarray is NOT instance of array');
           }
       };
       
    It seems like array's value is lost somewhere.
  2. Jick Steen 2012-01-19

    Same happens for example with a (myobject instanceof Object) check. Doesn't work.
  3. Sunila 2013-03-25

    I can't reproduce the problem, it works fine with SDK 3.1.0.
  4. Lee Morris 2017-03-21

    Closing ticket as the issue cannot be reproduced.

JSON Source