Closed Sytten closed 1 year ago
Haaaaaa, I managed to do it with creating an instance of SDK:
glob.set("__SDK", Class::instance(ctx, SDK::new())?)?;
It works no matter if I use Class::instance(ctx, Console::new())
or just Console::new()
which I guess makes sense since the proto is static?
I think some best practices / examples would go a long way!
🤦 Ok I realized the issue is with the #[derive(IntoJs]
So basically when it's autogenerated it will map the class into a JS class, but when you put:
impl<'js> IntoJs<'js> for SDK {
fn into_js(self, ctx: Ctx<'js>) -> Result<Value<'js>> {
self.into_js_obj(ctx)
}
}
It will automatically instantiate the class when converting it to JS! Thats why you dont need to call Class::instance
manually.
I hope this can help debug someone else...
Hi! I am trying to create nested objects, but I can't seem to do it. The
console
inside thesdk
is always undefined.I get the error:
I also tried to do:
But it doesn't work, I am a bit lost... Thanks!