Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Created November 23, 2013 05:24
Show Gist options
  • Select an option

  • Save bluepnume/7611141 to your computer and use it in GitHub Desktop.

Select an option

Save bluepnume/7611141 to your computer and use it in GitHub Desktop.
var util = require('util');
// Let's create a class with some abstract methods
function Animal() {
console.log('A new', this.name, 'is born!')
}
Animal.prototype.talk = function() {
console.log('The', this.name, 'goes', this.action)
}
// Now let's extend our abstract class
function Cat() {
}
util.inherits(Cat, Animal);
Cat.prototype.name = 'cat';
Cat.prototype.action = 'miaow';
function Kitten() {
}
util.inherits(Kitten, Cat);
Kitten.prototype.name = 'kitten';
function Dog() {
}
util.inherits(Dog, Animal);
Dog.prototype.name = 'dog';
Dog.prototype.action = 'woof';
// Now, let's generate some new objects using our classes
var mycat = new Cat;
var mykitten = new Kitten;
var mydog = new Dog;
mydog.action = 'woof woof woof'
// Now we can call the abstract methods for each of our objects
mycat.talk();
mykitten.talk();
mydog.talk();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment