Skip to content

Instantly share code, notes, and snippets.

View TheBox193's full-sized avatar
:shipit:
Shipping code.

Sir.Nathan (Jonathan Stassen) TheBox193

:shipit:
Shipping code.
View GitHub Profile
@TheBox193
TheBox193 / _.compactObject
Last active October 27, 2015 15:44
loDash.js and Underscore.js Mixins
/**
* Removes all falsy and undefined values from an object
* @param {object} o Object to be compacted
* @return {object} Compact Object
* @link http://stackoverflow.com/a/14058408/417822
*/
_.mixin({'compactObject': function(o) {
var clone = _.clone(o);
_.each(clone, function(v, k) {
@TheBox193
TheBox193 / gist:edb66f9e76d47d120bee
Last active August 29, 2015 14:18
Clean Backbone
Collection1 = Backbone.Collection.extend({
initialize: function(models, options){
// bad, causes things to crash if options.that doesn’t get passed.
this.doSomethingWithThat(options.that);
}
});
// Crashes since 'that' is not set
collection1 = new Collection1();