Created
November 14, 2016 02:04
-
-
Save deepakshrma/6b966c5384bb31a9f60b13e36871ccce to your computer and use it in GitHub Desktop.
Javascript Inheritance
This file contains hidden or 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
/** | |
* Created by intelligrape on 17/7/14. | |
*/ | |
Function.prototype.inherits = function (parent) { | |
"use strict"; | |
this.prototype = new parent(); | |
this.constructor = this; | |
this.prototype.parent = parent.prototype | |
} | |
function User(name) { | |
"use strict"; | |
var _uname = name; | |
this.getName = function () { | |
return _uname; | |
} | |
this.uinfo = "I am parent"; //public | |
} | |
User.prototype.getInfo = function () { | |
"use strict"; | |
return this.uinfo; | |
} | |
function Employee(name, salary) { | |
"use strict"; | |
var _uname = name; | |
this.getName = function () { | |
return _uname; | |
} | |
this.salary = 100; | |
this.getSalary = function () { | |
return salary; | |
} | |
this.setSalary = function (sal) { | |
salary = sal; | |
} | |
this.uinfo = "I am child..."; | |
} | |
Employee.inherits(User) | |
var user = new User("deepak"); | |
console.log(user.getName()) | |
console.log(user.getInfo()) | |
var employee = new Employee("rishabh"); | |
console.log(employee.getName()) | |
console.log(employee.getInfo()) | |
//console.log(employee.constructor.parent.getDatacall()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment