Last active
April 1, 2016 11:32
-
-
Save jsstrn/e46e4f5909bbbd205c4c0894a6776245 to your computer and use it in GitHub Desktop.
Object Oriented Programming in JavaScript
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
class Pet { | |
constructor () { | |
} | |
} |
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 Pet (name, born, died) { | |
this.name = name | |
this.born = born | |
this.died = died | |
} | |
Pet.prototype.age = function () { | |
return (this.died || new Date().getFullYear()) - this.born | |
} | |
function Dog (breed, name, born, died) { | |
Pet.apply(this, [name, born, died]) | |
this.breed = breed | |
} | |
Dog.prototype = Object.create(Pet.prototype) | |
var dog = new Dog('Jim', 'Labrador', 1990, null) |
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 Pet = { | |
init: function () { | |
} | |
} | |
var Dog = { | |
init: function (breed, options) { | |
Pet.init.call(this, breed, options) | |
this.breed = breed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment