1 #import "RootViewController.h" 2 #import <JavaScriptCore/JavaScriptCore.h> 3 4 @interface RootViewController ()<UIWebViewDelegate> 5 @end 6 7 @implementation RootViewController 8 9 - (void)viewDidLoad { 10 [super viewDidLoad]; 11 12 JSContext *context = [[JSContext alloc] init]; 13 [context evaluateScript:@"var square = function(x){return x*x;}"]; 14 JSValue *squareFunction = context[@"square"]; 15 JSValue *nineSquared = [squareFunction callWithArguments:@[@9]]; 16 NSLog(@"9^2:%@",nineSquared); 17 18 } 19 20 @end
时间: 2024-10-04 04:00:51