If I put a function into a string like this:
var functionString = function (message) {
console.log(message);
}.toString();
Is there any way to convert the string back to a function and call it? I tried
eval(functionString)
which returns "Uncaught SyntaxError: Unexpected token", and
functionString.call(this, "HI!");
which returns 'undefined is not a function'.
Is that even possible in javascript?
Thanks in advance for any reply!
EDIT: The point of this question is that the function has been converted into a string using toString(). So
console.log(functionString);
returns this string: "function (message) {console.log(message);}"
Can I transform the string back into a function and call it? That's the problem I am trying to solve. Thanks!