Skip to content

Instantly share code, notes, and snippets.

@logankoester
Created September 29, 2013 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logankoester/6749102 to your computer and use it in GitHub Desktop.
Save logankoester/6749102 to your computer and use it in GitHub Desktop.
Recursively map any functions to their returned value. This function will modify the passed object.
# Recursively map any functions to their returned value.
# This function will modify the passed object.
_.mixin
precompute: (object) ->
functions = @functions object
try
keys = @keys object
objects = @filter keys, (key) =>
@isObject(object[key])
catch
objects = []
@each functions, (func) =>
object[func] = object[func]()
@each objects, (child) =>
object[child] = @precompute object[child]
object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment