Created
December 15, 2010 18:59
-
-
Save orlin/742422 to your computer and use it in GitHub Desktop.
underscore.js with strings and other mixins (a node.js module)
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
| _ = 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