incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Mueller <pmue...@gmail.com>
Subject Re: `instanceof` considered harmful in cordova-js
Date Fri, 27 Apr 2012 18:28:00 GMT
On Fri, Apr 27, 2012 at 14:17, Filip Maj <fil@adobe.com> wrote:

> For reference: https://issues.apache.org/jira/browse/CB-588
>
> Essentially: using instanceof across windows (basically: iframes) is bad.
>

yes


> I'm leaning towards employing the toString() approach instead of a
> combination of typeof and duck-typing to fix this issue.
>

Without more context, hard to say.  Note the jQuery examples seem to only
be depending on the toString() hack for built-in types; presumably the
browsers have standardized on this a while ago.

If there is some kind of intention of making this work for "types" that we
define, then that's fragile; if you're calling toString() on the object
itself, no telling what you might get.  If you call
Object.prototype.toString() on the object, I think you're always going to
get [object Object], which of course tells you nothing.

I've seen a lot of folks do the Object.prototype.toString() thing to test
if something is an Array, which seems semi-valid to me.  All other "tests"
can be done via typeof and/or boolean expressions (===undefined, ===null,
isNaN(), etc)

That would be my general preference; resort to Object.prototype.toString()
as a last resort.

-- 
Patrick Mueller
http://muellerware.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message