Last active
August 29, 2015 14:01
-
-
Save tommymarshall/90f80f3f34d2d49bcbbd to your computer and use it in GitHub Desktop.
Compares Underscore's extend method with React's merge helper.
This file contains 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
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