name: duk_instanceof proto: | duk_bool_t duk_instanceof(duk_context *ctx, duk_idx_t index1, duk_idx_t index2); stack: | [ ... val1! ... val2! ... ] summary: |

Compare values at index1 and index2 using the Ecmascript instanceof operator. Returns 1 if val1 instanceof val2, 0 if not. Throws an error if either index is invalid; instanceof itself also throws errors for invalid argument types.

The error throwing behavior for invalid indices differs from the behavior of e.g. duk_equals(), and matches the strictness of instanceof. For example, if rval (index2) is not a callable object instanceof throws a TypeError. Throwing an error for an invalid index is consistent with instanceof strictness.
example: | duk_idx_t idx_val; duk_get_global_string(ctx, "Error"); if (duk_instanceof(ctx, idx_val, -1)) { printf("value at idx_val is an instanceof Error\n"); } tags: - compare introduced: 1.3.0