incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Maj <>
Subject `instanceof` considered harmful in cordova-js
Date Fri, 27 Apr 2012 18:17:14 GMT
For reference:

Essentially: using instanceof across windows (basically: iframes) is bad.
Daniel from the issue thread above posted a link [1] explaining the
underlying issue in a bit more detail.

In this specific example, GWT apps use an iframe to create initialization
callbacks and whatnot. Attaching these callbacks to deviceready (or other
cordova events) in the parent window doesn't work because instanceof
doesn't work across frames.

The link [1] offers a workaround: calling toString() on whatever you want
to check the instance of and comparing it against "[object
myPrototypeName]". My initial thought is, that seems weak, but taking a
look at jQuery source (see [2] and [3] together), they use this same
approach. That tells me it's pretty battle hardened.

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

I wanted to run it by the list to make sure this sounds alright and see if
anyone has any problems with this.



View raw message