Contents

JSObjectHasInstanceCallback

The callback type for checking whether an object is an instance of a particular type.

Declaration

typealias JSObjectHasInstanceCallback = (JSContextRef?, JSObjectRef?, JSValueRef?, UnsafeMutablePointer<JSValueRef?>?) -> Bool

Parameters

  • ctx:

    The execution context to use.

  • constructor:

    The Jsobjectref that is the target of the instanceof expression.

  • possibleInstance:

    The Jsvalueref to test to determine if it’s an instance of constructor.

  • exception:

    A pointer to a Jsvalueref to return an exception in, if any.

Return Value

true if possibleInstance is an instance of constructor according to the JavaScript instanceof expression; otherwise, false.

Discussion

If you name your function HasInstance, you declare it like this:

bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);

If the JavaScript expression someValue instanceof myObject invokes your callback, it sets constructor to myObject, and possibleInstance to someValue.

If this callback is NULL, instanceof expressions that target your object return false.

Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback, as well.

See Also

Managing Callbacks