Created
September 29, 2013 03:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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