evaluateScript:兼具js加载(生成具体的上下文)(函数与通用变量的加载),与函数执行的功能;

 

函数调用的方式有两种:

1)获取函数(对象),然后执行调用:

[context[@"appendString"] callWithArguments:@[@"hello"]];

2)直接在context中执行链式调用?:

[context evaluateScript:@"testFun('Greg', 18)"];

 

对象函数调用与上述类似,只是添加了对象限定:

//创建Person类的对象,将他赋值给js对象
Person *person=[Person new];
person.personName = @"Greg";
person.age = 27;
context[@"person"]=person;

//可以调用获取PersonProtocol暴露的内容
NSString *personName = [[context evaluateScript:@"person.personName"] toString]; //"Greg"
NSString *personName1 = [[context evaluateScript:@"person.queryPersonName()"] toString]; //"Greg"

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2019-01-26
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2021-06-04
  • 2021-07-25
  • 2021-08-24
  • 2022-12-23
  • 2022-01-24
  • 2021-11-01
  • 2021-08-25
相关资源
相似解决方案