The method will try to run the built-in javascript eval() in a string and if the string has some evaluation error it will throw a callback function passed also by the parameters. So it must be in a try catch. The method goes like below:
function tryEval(string_code: string, callback?: (error: Error) => void): any {
try {
return eval(string_code);
} catch (e) {
if (callback) {
callback(e);
} else {
throw e;
}
}
}
The method will try to run the built-in javascript eval() in a string and if the string has some evaluation error it will throw a callback function passed also by the parameters. So it must be in a try catch. The method goes like below:
Make sure to write some tests.