I wanted to implement a Node type like written below but I want to hide or protect the properties which aren’t functions so they can’t be over written from outside the class. Is this possible with Mootools hide and protect properties? and what is the difference between hide and protect in Mootools?
var Node = new Class({
initialize : function(name){
this.globalId = container.globalId++;
this.name = name || 'unnamed Node';
},
globalId : null,
siblingId : null,
name : null,
parentNode: null,
childrenNodes : [],
addChild : function(child){
//ensure it is a Node object
if(!instanceOf(child,Node)){
throw new Exception('Not a Node',this.name+':\nNode.globalId = '+this.globalId+
"\nAttempting to add a child node that is not a 'Node' type!");
}
child.parentNode = this;
child.siblingId = this.children.length;
this.children.push(child);
},
removeChild : function(child){
//ensure the child is my child!
if(child.parentNode !== this){
throw new Exception('Lost Child',this.name+':\nNode.globalId = '+this.globalId+
"\nAttempting to remove Node:\n"+child.name+":\nNode.globalId = "+child.globalId);
}
this.childrenNodes.splice(child.siblingId,1);
}
});
Node.globalId = 0;
If you need hidden properties, you can get them like this: