Last active
August 29, 2015 14:15
-
-
Save eliza-abraham/67c14b0eea6fdd8a11f5 to your computer and use it in GitHub Desktop.
Object Oriented JavaScript : Classical Approach
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
// 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