Skip to content

Instantly share code, notes, and snippets.

@egobrain
Last active December 20, 2015 05:38
Show Gist options
  • Save egobrain/6079357 to your computer and use it in GitHub Desktop.
Save egobrain/6079357 to your computer and use it in GitHub Desktop.
Call only last defined function wrapper (Coffee)
CallOnceConstructor = ->
cache = {}
(f) ->
cache.f_link?.f = null
f_link = f: f
cache.f_link = f_link
-> f_link.f?.apply null, arguments
# example
# call_last = CallOnceConstructor()
# f1 = call_last(...)
# f2 = call_last(...)
# f3 = call_last(...)
# only f3 will be performed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment