Last active
February 2, 2016 04:11
-
-
Save joshwcomeau/4799edafc883cd9f6da3 to your computer and use it in GitHub Desktop.
An example of concatenative inheritance
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 animal = { | |
position: [0,0], | |
species: "mammal", | |
move: function(distance, axis) { | |
axis === 'x' | |
? this.position[0] += distance | |
: this.position[1] += distance; | |
} | |
} | |
var dog = _.extend({}, animal, { | |
species: "canine", | |
bark: function() { | |
alert("woof!"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of lodash _.extend in ES6/2015 you can know use Object.assign()