我想实现如下所示的 Node 类型,但我想隐藏或保护不是函数的属性,因此不能从类外部覆盖它们。Mootools 可以隐藏和保护属性吗?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;