Positionable


TypeScript Mixins OOP Public New

Hard  

3min


Consider the following two base classes, Positionable and Rotatable, and MovingObject derived class:

class Positionable {
    locationX: number;
    locationY: number;
}

class Rotatable {
    orientation: number;
    rotate(orientation: number) {
        this.orientation += orientation;
    }
    align(rotatable: Rotatable) {
        this.orientation = rotatable.orientation;
    }
}

class MovingObject implements Positionable, Rotatable {
    locationX: number = 0;
    locationY: number = 0;
    orientation: number = 0;
    rotate: (orientation: number) => void;
}

applyMixins(MovingObject, [Positionable, Rotatable]);
function applyMixins(derivedCtor: any, baseCtors: any[]) {
    baseCtors.forEach(baseCtor => {
        Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
            derivedCtor.prototype[name] = baseCtor.prototype[name];
        });
    });
}

let mover = new MovingObject(); 
mover.rotate(30);

Select all the statements that are correct.