Tag Archives: inheritance

Taking a close look at inheritance and closures in Javascript

Let’s play with inheritance and closures in Javascript. Take a look at the following javascript code: function BaseClass(){ var id=200; this.Id=function(){ return id; } } function ChildClass(){ var id=500; } ChildClass.prototype = new BaseClass(); var childObject=new ChildClass(); In Javascript, inheritance is achieved using prototype. When we try to access any member on Javascript object, it [...]