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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -