Skip to content

Instantly share code, notes, and snippets.

@jakcharlton
Created May 25, 2011 09:14
Show Gist options
  • Save jakcharlton/990648 to your computer and use it in GitHub Desktop.
Save jakcharlton/990648 to your computer and use it in GitHub Desktop.
How do I return 'data' as the result of save_it ?
# How do I return 'data' as the result of save_it ?
save_it = (edited_value, s) ->
$.post(url_to_save_to, {value: edited_value}, (data) -> data)
@TrevorBurnham
Copy link

By the way, if instead of $.post you were calling something that synchronously runs its callback, then you could write

save_it = (edited_value, s) ->
  data = null
  runNow (d) -> data = d
  data

to return the value provided by runNow from save_it. (The data = null line is necessary to give data scope outside of the callback.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment