I am grappling with a JavaScript function structured like this.
function getState(){
return "Hello";
}
var cryptico = (function() {
var my = {};
my.generateRSAKey = function(passphrase, bitlength)
{
Math.seedrandom(sha256.hex(passphrase));
var rsa = new RSAKey();
rsa.generate(bitlength, "03");
return rsa;
}
}());
If the function were declared outside, calling it would be simple.
NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"cryptico" ofType:@"js"];
NSString *scriptString = [NSString stringWithContentsOfFile:jsPath encoding:NSUTF8StringEncoding error:nil];
JSContext *context = [[JSContext alloc] init];
context = [[JSContext alloc] init];
[context evaluateScript:scriptString];
JSValue *test10 = context[@"getState"];
JSValue *test11 = [test10 callWithArguments:@[]]; //will be Hello
The challenge arises when attempting to invoke something stored within a variable. Despite several attempts using various methods, I have been unable to achieve the desired outcome.