Skip to content

Instantly share code, notes, and snippets.

@iShafayet
Created July 24, 2015 06:02
Show Gist options
  • Save iShafayet/e881bc886baf98086644 to your computer and use it in GitHub Desktop.
Save iShafayet/e881bc886baf98086644 to your computer and use it in GitHub Desktop.
Serializing/Deserializing Javascript Functions with eval
@__deserializeFunction = __deserializeFunction = (argumentArray)->
Function.apply {}, argumentArray
@__serializeFunction = __serializeFunction = (fn)->
deSF = fn.toString()
temp = deSF.indexOf '('
temp1 = deSF.indexOf ')'
declaration = deSF.substring temp+1, temp1
args = declaration.split ', '
temp = deSF.indexOf '{'
temp1 = deSF.lastIndexOf '}'
body = deSF.substring temp+1, temp1
args.push body
return args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment