I'm writing a binding generator for C++ <-> ChakraCore. Right now, I'm struggling to support extending native classes from JS-defined classes like so:
class JavascriptChildClass extends NativeSuperClass {
constructor() {
super();
}
TestChildMethod() {
console.log("Oops!");
}
}
However, when I return the object generated from NativeSuperClass's native constructor, I have to call JsSetPrototype on it in order to properly bind the native class to its JS prototype.
I'd like to attach the prototype of "JavascriptChildClass" instead. Right now, I can't find any way to do that, and so the methods on the child class are lost, i.e., TestChildMethod can't be called.
I can't figure out any way to get JavascriptChildClass's prototype from a native context in order to properly set it when "super" is called. It doesn't seem to be, "callee.prototype", "callee.__proto__", or "arguments[0].__proto__", or anything returned from JsGetPrototype on either callee or arguments[0].
Any ideas? Am I doing this completely incorrectly?
I managed to figure this out.
The "arguments[0]" object (this) passed in is actually the function that represents the class (JavascriptChildClass constructor in this case, somewhat unintuitively, but maybe only because I'm not super experienced with Javascript), so the "prototype" property on arguments[0] ("this" object) is what I'm looking for here.
Closing and hopefully this knowledge might help someone else in the future :)
note to anyone who encounters this issue in the future and finds this: this is true, the thumbs down are from my dickhead friends