利用JavaScriptCore实现以下简单的功能(平方和)
2015-07-16 09:55 甘雨路 阅读(155) 评论(0) 编辑 收藏 举报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