I am wondering if there is a way to add new methods to prototype of string in Neil Fraser's JS-Interpreter. The documentation has no example for this and I am not really able to figure it out by the source code.
I expect (if there is a way) to be something similar to adding API calls to the interpreter's global object during creation.
What I have tried is the following:
const interpreter = require('js-interpreter');
var initFunc = function (interpreter, globalObject) {
var stringPrototype = interpreter.nativeToPseudo(String.prototype);
var stringGreetWrapper = function greet() {
return "Hi " + this + "!";
};
interpreter.setProperty(stringPrototype, 'greet', interpreter.createNativeFunction(stringGreetWrapper));
};
var code = 'function foo(name) {return name.greet();}';
var myInterpreter = new interpreter(code, initFunc);
myInterpreter.appendCode('foo("John");');
myInterpreter.run();
var res = myIntepreter.value;
But it gives me an error: "undefined is not a function"