Created
December 12, 2012 08:49
-
-
Save datapimp/4266192 to your computer and use it in GitHub Desktop.
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
| # Takes an string like "deep.nested.value" and an object like window | |
| # and returns the value of window.deep.nested.value. useful for defining | |
| # references on objects which don't yet exist, as strings, which get | |
| # evaluated at runtime when such references will be available | |
| Luca.util.resolve = (propertyReference, source_object)-> | |
| return propertyReference unless _.isString(propertyReference) | |
| try | |
| source_object ||= (window || global) | |
| resolved = _( propertyReference.split(/\./) ).inject (obj,key)-> | |
| obj = obj?[key] | |
| , source_object | |
| catch e | |
| console.log "Error resolving", propertyReference, source_object | |
| throw e | |
| resolved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment