Skip to content

Instantly share code, notes, and snippets.

@jsstrn
Last active April 1, 2016 11:32
Show Gist options
  • Save jsstrn/e46e4f5909bbbd205c4c0894a6776245 to your computer and use it in GitHub Desktop.
Save jsstrn/e46e4f5909bbbd205c4c0894a6776245 to your computer and use it in GitHub Desktop.
Object Oriented Programming in JavaScript
class Pet {
constructor () {
}
}
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)
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