利用JavaScriptCore实现以下简单的功能(平方和)

 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

 

你可能感兴趣的:(JavaScript)