Skip to content

Instantly share code, notes, and snippets.

@orlin
Created December 15, 2010 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlin/742422 to your computer and use it in GitHub Desktop.
Save orlin/742422 to your computer and use it in GitHub Desktop.
underscore.js with strings and other mixins (a node.js module)
define (require, exports, module) ->
_ = require("underscore")
_.mixin require("underscore.string")
_.mixin
# Converts the arguments list to an Array
aToArr: (list) ->
if _.isArguments(list)
_.toArray(list).slice(0)
else
console.log "aToArr called with these non-arguments: #{list}"
[list]
# Merges all from a list of objects in return for a single one
# sequentially overwrites keys (with disrespect for nested values)
allFurther: (into, rest...) ->
# _.each rest, (item) -> _.map item, (val, key) -> into[key] = val
for item in rest
for key, val of item
into[key] = val
into
module.exports = _
var __slice = Array.prototype.slice;
define(function(require, exports, module) {
var _;
_ = require("underscore");
_.mixin(require("underscore.string"));
_.mixin({
aToArr: function(list) {
if (_.isArguments(list)) {
return _.toArray(list).slice(0);
} else {
console.log("aToArr called with these non-arguments: " + list);
return [list];
}
},
allFurther: function() {
var into, item, key, rest, val, _i, _len;
into = arguments[0], rest = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
for (_i = 0, _len = rest.length; _i < _len; _i++) {
item = rest[_i];
for (key in item) {
val = item[key];
into[key] = val;
}
}
return into;
}
});
return module.exports = _;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment