Private, Public & Inheritance in JS
by Dhiviya Dhanasekar
JavaScript
var Node = (function(){
var value; //private var
var nextNode;
this.test = null;
return function(){
this.setValue = function(val){
value = val;
console.log(value);
}
this.setNextNode = function(node){
nextNode = node;
}
}
})();
var TreeNode = function(){
this.val = null; //public var
this.left = null;
this.right = null;
};
TreeNode.prototype = new Node(); //Treenode inherits from Node
var tnode = new TreeNode();
console.log(tnode.setValue(123));
/*var a = [];
var n1 = new Node();
console.log(n1);
n1.setValue(1);
a.push(n1);
n1.setValue(2); */