We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

JS HasInstance

JSAPI method equivalent to the instanceof operator in JavaScript.


JSBool JS_HasInstance(JSContext *cx, JSObject *obj, jsval *v, JSBool *bp);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * Constructor/prototype to test.
v jsval * The value to test.
bp JSBool * Out parameter. On success, *bp receives the result of the test.


JS_HasInstance determines if a specified JS value, v, is an instance of JS object, obj. This function is equivalent to v instanceof obj test in JavaScript.  On success, JS_HasInstance stores the result of the instanceof test in *bp and returns JS_TRUE. On error or exception, it returns JS_FALSE, and the value left in *bp is undefined.

When providing a prototype as obj, the prototype's JSClass must have its hasInstance method set. Otherwise JS_HasInstance returns JS_FALSE.

MXR ID Search for JS_HasInstance

Document Tags and Contributors

Last updated by: ethertank,