Skip to content

Instantly share code, notes, and snippets.

@IftekherSunny
Created September 3, 2015 05:02
Show Gist options
  • Save IftekherSunny/bf062839c82d664154af to your computer and use it in GitHub Desktop.
Save IftekherSunny/bf062839c82d664154af to your computer and use it in GitHub Desktop.
<!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