How to define a local function in Constructor.prototype in Javascript -
hi guys facing difficulty in 1 of scenario in m not able define local function in manager.prototype. please find below detail..
i have constructor function employee.
function employee(id){ this.id = id; } employee.prototype.getid = function(){ return this.id; } var mark = new employee(123);
again have manager constructor
function manager(managerof){ this.managerof = managerof; } manager.prototype = object.create(employee.prototype); manager.prototype.getmanagerof = function(){ return this.managerof; } var john = new manager(mark);
now want define function calcsalary() accessible getmanagerof() method & not outside. [john.calcsalary() should not work]
you hide self executing function.
var manager = (function() { function calcsalary() {} function manager(managerof){ this.managerof = managerof; } manager.prototype = object.create(employee.prototype); manager.prototype.getmanagerof = function(){ // call calcsalary return this.managerof; } return manager; }()); var john = new manager(mark);
Comments
Post a Comment