Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommymarshall/90f80f3f34d2d49bcbbd to your computer and use it in GitHub Desktop.
Save tommymarshall/90f80f3f34d2d49bcbbd to your computer and use it in GitHub Desktop.
Compares Underscore's extend method with React's merge helper.
var merge = require('react/lib/merge');
var _ = require('underscore');
var a = {
name: 'Tommy',
specs: {
height: {
inches: 60,
feet: 6.085
},
weight: 180
}
};
var b = {
name: 'Lawson',
specs: {
height: {
inches: 62
},
weight: 190
},
actions: {
play: function() {
console.log('go play');
}
}
};
var c = function(){};
c.prototype.play = function() {
console.log('c play');
};
var reactsMethod = merge(c.prototype,a);
var underscoresMethod = _.extend(c.prototype,a);
console.log(reactsMethod);
console.log(underscoresMethod);
console.log( JSON.stringify(reactsMethod) === JSON.stringify(underscoresMethod) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment