Subj : Re: Using JS_InstanceOf with jsval's To : netscape.public.mozilla.jseng From : Brendan Eich Date : Tue Jan 20 2004 03:17 pm Brendan Eich wrote: > If you want an API to tell what the instanceof operator's result would > be, use this: > > JSObject *b = JSVAL_TO_OBJECT(bval); > JSObject *B = JS_GetConstructor(cx, b); > JSBool answer; > JS_GET_CLASS(cx, B)->hasInstance(cx, B, JSVAL_TO_OBJECT(aval), > &answer); I was typing from memory, but got the third argument's type wrong; Mike kindly set me straight in email: JS_GET_CLASS(cx, B)->hasInstance(cx, B, aval, &answer); The type is jsval, not JSObject *. This allows an object to say that it has any value as an instance, although currently only object values are considered instances of functions (class constructors whose .prototype property references an object on the __proto__ chain of the object value). /be .