arrays are not objects?

Posted on
  • I'm trying to port a deepEqual function to compare two objects and I encountered this problem. In Espruino:

    >var a = [1,2]
    =[ 1, 2 ]
    >a instanceof Object
    =false
    

    in Chrome:

    var a = [1,2]
    undefined
    a instanceof Object
    true
    

    Is there already a deepEqual function for Espruino? I want it to compare the output of test code...

  • Depends what you're doing, but you could just convert both objects to a String with JSON.stringify and compare the strings?

    Can you file a bug for instanceof? I'm kind of surprised about that - I thought those kind of issues had been ironed out a while back.

    I think in JS, an array is Array, which is also an instance of Object. Espruino currently has a bit of a shonky prototype chain implementation, and it's possible instanceof has fallen foul of that.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

arrays are not objects?

Posted by Avatar for tve @tve

Actions