Skip to content

Instantly share code, notes, and snippets.

@orlin
Created December 15, 2010 18:59
Show Gist options
  • Select an option

  • Save orlin/742422 to your computer and use it in GitHub Desktop.

Select an option

Save orlin/742422 to your computer and use it in GitHub Desktop.
underscore.js with strings and other mixins (a node.js module)
_ = require("underscore")
_.mixin require("underscore.strings")
_.mixin
# Converts arguments to plain Array
aToArr: (list) ->
if _.isArguments(list)
_.toArray(list).slice(0)[0]
else
console.log "aToArr called with these non-arguments: #{list}"
[list]
# Merges an array of objects (sequentially overwrites with disrespect for nested values)
merge: ->
args = _(arguments).aToArr()
into = _.first args
for item in _.rest args
for key, val of item
into[key] = val
into
module.exports = _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment