Skip to content
Discussion options

You must be logged in to vote

There's no concept of inheritance at the C API level but you can distinguish between types in your C callback:

JSValue callback(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
    Inherit *inherit;
    Base *base;

    if ((inherit = JS_GetOpaque(this_val, inherit_classid))) {
        // called as Inherit method
    } else if ((base = JS_GetOpaque(this_val, base_classid))) { // JS_GetOpaque2 if it should throw TypeError
        // called as Base method
    } else {
        // called as something else, maybe throw a TypeError
    }
   // ...
}

As to constructor inheritance, just call the constructor function manually:

JSValue base_constructor(JSContext *ctx, JSValueC…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by neko-para
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants