JS InstanceOf
From MDC
Determines if an object is an instance of a specified JS class.
[edit] Syntax
JSBool JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
Pointer to a JS context from which to derive runtime information.
Requires request. (In a |
obj |
JSObject * |
Object to test. |
clasp |
JSClass * |
Class against which to test the object. |
argv |
jsval * |
Optional argument vector. If non-null, report an error if obj is not of type clasp. argv must be the argv argument passed from the engine to a JSNative callback, JS_ARGV(cx, rv) in a JSFastNative callback, or NULL. |
[edit] Description
JS_InstanceOf determines if a specified JS object, obj, has a JS class struct, clasp. If the object's internal class pointer corresponds to clasp, this function returns JS_TRUE, indicating that the object is an instance of the class. Otherwise, JS_InstanceOf returns JS_FALSE.
If argv is non-null and obj is not an instance of clasp, this function may report a class mismatch before returning. To do so, JS_InstanceOf tests whether or not there is a function name associated with the argument vector. If so, it reports the name in an error message using the JS_ReportError function.
Note that JS_InstanceOf is not the equivalent of the JavaScript instanceof keyword, which examines constructor properties along the prototype chain. JS_HasInstance is similar to instanceof.