Created
September 3, 2015 05:02
-
-
Save IftekherSunny/bf062839c82d664154af to your computer and use it in GitHub Desktop.
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>JavaScript Class & Inheritance</title> | |
</head> | |
<body> | |
<script> | |
// Create Person class | |
var ClassPerson = function (name) { | |
// Person has a name property | |
this.name = name; | |
// Person has a getName method | |
this.getName = function () { | |
} | |
} | |
// Create Employee Class | |
// Employee Class extends Person class | |
var ClassEmployee = function (name) { | |
// Initialize person class | |
this.person = new ClassPerson(name) | |
// Override person class getName method | |
this.getName = function() { | |
console.log(this.person.name); | |
} | |
} | |
/** | |
* To show output | |
* | |
* @type {ClassEmployee} | |
*/ | |
var employee = new ClassEmployee('sunny'); | |
// call getName method of the ClassEmployee | |
// output will be sunny | |
employee.getName(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment