Last active
August 29, 2015 14:01
-
-
Save dmi3y/64d0808d7a137a874934 to your computer and use it in GitHub Desktop.
From Car to Honda
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
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'); |
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
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'}}); |
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
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