-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问setProperty的对象怎么支持instanceof #85
Comments
没太明白你的问题,可以举个例子吗 |
QuickJSLoader.init();
QuickJSContext context = QuickJSContext.create();
context.setConsole(new JSConsole(false));
JSObject global = context.getGlobalObject();
// 这里如何定义一个js类
global.setProperty("MyClass", MyClass.class);
global.setProperty("ins", new MyClass());
context.evaluate("""
let mc = new MyClass();
if (ins instanceof MyClass) {
console.log("success")
}
""");
context.destroy(); 就是类似这种,我可以在Java定义一个类,这个类可以在Java里new,也可以在js中new,且它们的原型是同一个,非常感谢 |
QuickJSContext context = QuickJSContext.create();
context.setConsole(new JSConsole(false));
JSObject globalObj = context.getGlobalObject();
var prototype = context.createNewJSObject();
var object = context.createNewJSObject();
object.setProperty("__proto__", prototype);
globalObj.setProperty("obj", object);
var clazz = context.createNewJSObject();
clazz.setProperty("prototype", prototype);
globalObj.setProperty("ObjClass", clazz);
context.evaluate("""
if(obj instanceof ObjClass){
console.log('yes')
}
""");
context.destroy(); 如果我使用相同原型链对象的话,会报错 |
明白了,不过这个能力目前还不支持 😂 |
好的,感谢 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
obj instanceof OutObject
请问OutObject使用Java定义,怎么实现instanceof功能?非常感谢
The text was updated successfully, but these errors were encountered: