Unsolved Help with JavaScript type
-
I'm asking this here because it may be peculiar to the QML JavaScript engine.
What value of
x
could give me the following results:x !== null
x !== undefined
typeof x === "object"
String(x) === "?"
Object.getPrototypeOf(x) === undefined
In my program
x
could benull
, but the first test says otherwise, or it could be aUint8Array
, but the string version of that is a comma-separated list of numbers. What, other than a quoted question mark, displays as a question mark?I'm wondering if it could be a reference to an object that has been garbage collected, and I've discovered some sort of bug in the engine.
-
Hi,
Can you post a minimal code sample that shows the situation you describe ?
-
@pderocco
Don't know, but don't forget you can try variousinstanceOf()
if you can guess what the (base) type might be? -
@SGaist Unfortunately, when I try a simple program that does what the real program is (supposedly) doing, it works fine. So I'm trying to deduce it from the other end, by figuring out what the type of the object is.
-
@JonB The only two things I should get are null or a Uint8Array. When the failure occurs, it doesn't compare equal to null, and
x instanceof Uint8Array
returnsfalse
. Also,x.prototype
returnsundefined
. Other thannull
, what kinds of things can report a type ofobject
, but not have a prototype?Update: Apparently, things like Uint8Array report a type of
object
, and have aprototype
ofundefined
rather thannull
. I guessed that I may have used an ArrayBuffer instead of a Uint8Array, and sure enough,x instanceof ArrayBuffer
returns true. Soconsole.log
displays anArrayBuffer
as a question mark.So, problem solved I guess. Thanks for pointing me to
instanceof
. -
@pderocco
Yep, that's why I suggestedinstanceOf()
:) JS is odd!