src/composites/Tree.js
function Tree(type) {
    abstractions.Composite.call(this, type);
    if (!utilities.types.isProcedural(type)) {
        throw new utilities.Exception({
            $module: '/bali/composites/Tree',
            $procedure: '$Tree',
            $exception: '$invalidParameter',
            $parameter: utilities.types.symbolForType(type),
            $text: '"An invalid tree type was passed to the constructor."'
        });
    }

    // the array is a private attribute so methods that use it are defined in the constructor
    const array = [];

    this.toArray = function() {
        return array.slice(); // copy the array
    };

    this.getSize = function() {
        return array.length;
    };

    this.addChild = function(child) {
        array.push(child);
        child.getParent = function() { return this; };
    };

    this.getChild = function(index) {
        index = this.normalizeIndex(index) - 1;  // JS uses zero based indexing
        return array[index];
    };

    this.getParent = function() { };  // will be reset by parent when added as a child

    return this;
}
function Tree(type) {
    abstractions.Composite.call(this, type);
    if (!utilities.types.isProcedural(type)) {
        throw new utilities.Exception({
            $module: '/bali/composites/Tree',
            $procedure: '$Tree',
            $exception: '$invalidParameter',
            $parameter: utilities.types.symbolForType(type),
            $text: '"An invalid tree type was passed to the constructor."'
        });
    }

    // the array is a private attribute so methods that use it are defined in the constructor
    const array = [];

    this.toArray = function() {
        return array.slice(); // copy the array
    };

    this.getSize = function() {
        return array.length;
    };

    this.addChild = function(child) {
        array.push(child);
        child.getParent = function() { return this; };
    };

    this.getChild = function(index) {
        index = this.normalizeIndex(index) - 1;  // JS uses zero based indexing
        return array[index];
    };

    this.getParent = function() { };  // will be reset by parent when added as a child

    return this;
}
function Tree ( type ) { abstractions . Composite . call ( this , type ) ; if ( ! utilities . types . isProcedural ( type ) ) { throw new utilities . Exception ( { $module : '/bali/composites/Tree' , $procedure : '$Tree' , $exception : '$invalidParameter' , $parameter : utilities . types . symbolForType ( type ) , $text : '"An invalid tree type was passed to the constructor."' } ) ; } // the array is a private attribute so methods that use it are defined in the constructor const array = [ ] ; this . toArray = function ( ) { return array . slice ( ) ; // copy the array } ; this . getSize = function ( ) { return array . length ; } ; this . addChild = function ( child ) { array . push ( child ) ; child . getParent = function ( ) { return this ; } ; } ; this . getChild = function ( index ) { index = this . normalizeIndex ( index ) - 1 ; // JS uses zero based indexing return array [ index ] ; } ; this . getParent = function ( ) { } ; // will be reset by parent when added as a child return this ; }
PUBLIC FUNCTIONS 
This constructor creates a new tree node component.

@param {Number} type The type of the tree node component.
@returns {Tree} The new tree node component.
PUBLIC FUNCTIONS This constructor creates a new tree node component .