Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

instanceof on wrappedJSObject

7 views
Skip to first unread message

Steven Roussey

unread,
Sep 16, 2010, 5:50:18 PM9/16/10
to
Say in an extension I have window variable. To get the user's view of
it:

var win = window.wrappedJSObject;

Now why does this not work most* of the time:

var a = win.Object;
var b = new a();
var c = b instanceof a;

How do I do the above to get the result that c==true instead of
throwing "invalid 'instanceof' operand"?

Thanks...
-s

* The times it does work, requires chromebug to be installed and
actively adding some things to the watch panel

Steven Roussey

unread,
Sep 17, 2010, 2:21:25 PM9/17/10
to
One solution should anyone have the same issue, is to create your own
instanceof:

function instanceOf(object, Klass)
{
while (object != null)
{
if (object == Klass.prototype)
return true;
object = object.__proto__;
}
return false;
}

-s

Blake Kaplan

unread,
Sep 17, 2010, 6:43:35 PM9/17/10
to
Steven Roussey <srou...@gmail.com> wrote:
> How do I do the above to get the result that c==true instead of
> throwing "invalid 'instanceof' operand"?

The above should work. Please file a bug with a testcase?
--
Blake Kaplan

0 new messages