Is it okay to do the following:
// Response from an API as a string, that contains a function to call.
const stringFunc = 'myFunc({"Status":200,"Message":"This is a message"})';
function myFunc(obj) {
console.log(obj);
}
function callBack(stringFn) {
return Function.prototype.call(stringFn);
}
callBack(stringFunc);
Console logs:
{"Status":200,"Message":"This is a message"}
It seems to work just fine, but wanted to know if this was the correct way to go about this at all? Are there any better methods or unforeseen implications?
Thanks