I’m trying to save a function into a JSON and load it back.
My code is as following :
import { Style } from 'external-lib'
function testFunction() { return new Style(); }
var str = String(testFunction);
//Converting testFunction to string using String(testFunction) result in the following :
function testFunction(feature, resolution) {
return new external_lib_style_WEBPACK_IMPORTED_MODULE_9__["default"]();
}
//In order to convert string to a function again, i'm using :
var fn = Function('return ' + str)();
fn(); //<------------ "lib_style_WEBPACK_IMPORTED_MODULE_9__ is not defined
I struggle to understand why lib_style_WEBPACK_IMPORTED_MODULE_9__ cannot be resolved as it is in the current context.
I tried the dumb solution of replacing lib_style_WEBPACK_IMPORTED_MODULE_9__[“default”] by Style but the result is the same, it throws Style is not defined.
Am I missing something there ?
Thanks and have a nice day !