Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

JS_HasInstance

This article needs a technical review. How you can help.

JSAPI method equivalent to the instanceof operator in JavaScript.

Syntax

bool
JS_HasInstance(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<JS::Value> v, bool *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 JS::Handle<JSObject*> Constructor/prototype to test.
v JS::Handle<JS::Value> The value to test.
bp bool * Out parameter. On success, *bp receives the result of the test.

Description

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 true. On error or exception, it returns 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 false.

See Also

Document Tags and Contributors

 Contributors to this page: arai, fscholz, kscarfone, ethertank
 Last updated by: arai,