gpt4 book ai didi

objective-c - 如何检查 JSValue 是否是一个函数

转载 作者:行者123 更新时间:2023-12-02 20:48:04 26 4
gpt4 key购买 nike

我正在使用 JavaScriptCore 与 Objective-C 代码交互

JSValue 中没有 isFunction 方法,但我想检查 JSValue 是否是 JS Function 并从 Objective-C 调用它

最佳答案

我最终注入(inject)了一小段 JavaScript 代码来返回 typeof 的结果

[context evaluateScript:@"function is(obj){ return typeof obj }"];
JSValue *is = [[context globalObject] valueForProperty:@"is"];
JSValue *type = [is callWithArguments:@[ is ]];

关于objective-c - 如何检查 JSValue 是否是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43425751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com