Skip to content

Instantly share code, notes, and snippets.

@perplexes
Created February 16, 2010 01:01
Show Gist options
  • Save perplexes/305169 to your computer and use it in GitHub Desktop.
Save perplexes/305169 to your computer and use it in GitHub Desktop.
Object.prototype.tap: (func) ->
func.apply(this, [this])
Object.prototype.clone: ->
((this instanceof Array) ? [] : {}).tap (newObj) =>
for key, val of this
if key == 'clone'
# no op
else if val && typeof val == 'object'
newObj[key] = val.clone()
else
newObj[key] = val
Object.prototype.merge: (obj) ->
@clone().tap (newObj) ->
for key, val of obj
newObj[key] = val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment