module.exports = class Node extends require './base'module.exports = class Node extends require './base' constructor: -> super appendChild: (child) ->If the child is not this instance
if child isnt thisinitialize the #children if necessary.
@children ||= []If child isnt already int the children list,
if -1 is @children.indexOf childremove the child from it’s parent if it has one
child.parent?.removeChild? childand update the child’s parent.
child.parent = thisFinally, append the child to the #children list.
@children.push child
return thisRemoves the child from the #children.
removeChild: (child) ->If there are any children and the child belongs to this parent
if @children?.length and -1 isnt idx = @children.indexOf childmake the child forget about it’s parent
delete child.parentand remove the child from #children.
@children.splice idx, 1Delete the #children if it is empty.
delete @children if @children.length is 0
return this