Skip to content

Instantly share code, notes, and snippets.

@de314
Last active July 4, 2018 15:06
Show Gist options
  • Save de314/c07ab5ff4be4157d59f0beb488bb409b to your computer and use it in GitHub Desktop.
Save de314/c07ab5ff4be4157d59f0beb488bb409b to your computer and use it in GitHub Desktop.
function test() { return 'Hello, World!' }
function fromFunc(func) { return func.toString() }
function toFunc(funcString) { return new Function(`return ${funcString.toString()}`)() }
let tmp = fromFunc(test)
// tmp = "function test() { console.log('Hello, World!') }"
tmp = toFunc(tmp)
tmp()
// Hello, World!
function _alert(m) { alert(m) }
toFunc(fromFunc(_alert))('Hello, World!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment