Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save bluepnume/7611045 to your computer and use it in GitHub Desktop.
// Let's create a class with some abstract methods
var Animal = Class.extend({
init: function() {
console.log('A new', this.name, 'is born!')
},
talk: function() {
console.log('The', this.name, 'goes', this.action)
}
})
// Now let's extend our abstract class
var Cat = Animal.extend({
name: 'cat',
action: 'miaow'
})
var Kitten = Cat.extend({
name: 'kitten'
})
var Dog = Animal.extend({
name: 'dog',
action: 'woof'
})
// Now, let's generate some new objects using our classes
var mycat = new Cat;
var mykitten = new Kitten;
var mydog = new Dog({
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