Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Last active February 2, 2016 04:11
Show Gist options
  • Save joshwcomeau/4799edafc883cd9f6da3 to your computer and use it in GitHub Desktop.
Save joshwcomeau/4799edafc883cd9f6da3 to your computer and use it in GitHub Desktop.
An example of concatenative inheritance
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!");
}
});
@bencooling
Copy link

Instead of lodash _.extend in ES6/2015 you can know use Object.assign()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment