Skip to content

Instantly share code, notes, and snippets.

@dmi3y
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 dmi3y/64d0808d7a137a874934 to your computer and use it in GitHub Desktop.
Save dmi3y/64d0808d7a137a874934 to your computer and use it in GitHub Desktop.
From Car to Honda
function Car (col) {
var color = col || 'white';
return {
paint: function (col) {
color = col;
},
getColor: function() {
return color;
}
};
}
function Honda (make) {
var honda = Car();
honda.make = make;
return honda;
}
hondaCRV = Honda('CR-V');
Car = {
color: 'white',
paint: function (col) {
this.color = col;
}
};
Honda = Object.create(Car);
Honda.model = function() {return this.make;};
hondaCRV = Object.create(Honda, {make: {value: 'CR-V'}});
function Car (color) {
this.color = color || 'white';
}
Car.prototype.paint = function (color) {
this.color = color;
};
function Honda (make) {
this.make = make;
}
Honda.prototype = new Car();
hondaCRV = new Honda('CR-V');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment