Skip to content

Instantly share code, notes, and snippets.

@eliza-abraham
Last active August 29, 2015 14:15
Show Gist options
  • Save eliza-abraham/67c14b0eea6fdd8a11f5 to your computer and use it in GitHub Desktop.
Save eliza-abraham/67c14b0eea6fdd8a11f5 to your computer and use it in GitHub Desktop.
Object Oriented JavaScript : Classical Approach
// Classical Approach
var Dog = function(name, breed, age, origin){
this.name = name;
this.breed = breed;
this.age = age
this.origin = origin
this.bark = function() {
return('bow wow!');
}
this.roll = function() {
return(this.name + ' rolls over');
}
}
var rover = new Dog('Rover', 'Pitbul', '3', 'England');
var lass = new Dog('Lass', 'Boxer', '3', 'India');
// Overides the prototype method
lass.bark = function(){
return('woof!');
}
rover.bark(); // bow wow!
lass.bark(); // woof!
rover.roll(); // Rover rolls over
lass.roll(); // Lass rolls over
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment