Skip to content

Instantly share code, notes, and snippets.

@saidinesh5
saidinesh5 / apply_defaults.coffee
Created February 18, 2012 17:44
A Useful coffeescript "defaults" function , which even does type checking.
applyDefaults = (source, defaults) ->
###
# Recursively applies defaults to the source object
###
#The Mandatory safety checks
return source if not source?
return defaults if not defaults?
#First fill the results with defaults of each proprerty, recursively
result = {}
for prop of defaults