In my Typescript code, I encountered an error with the line child._moveDeltaX(delta)
. The error message reads:
ERROR: Property '_moveDeltaX' is protected and only accesible
through an instance of class 'Container'
INFO: (method) Drawable._moveDeltaX( delta:number):void
The code snippet causing this error is as follows:
class Drawable {
private _x:number = 0;
constructor() {}
/**
* Moves the instance a delta X number of pixels
*/
protected _moveDeltaX( delta:number):void {
this._x += delta;
}
}
class Container extends Drawable {
// List of children of the Container object
private childs:Array<Drawable> = [];
constructor(){ super();}
protected _moveDeltaX( delta:number ):void {
super._moveDeltaX(delta);
this.childs.forEach( child => {
// ERROR: Property '_moveDeltaX' is protected and only accesible
// through an instance of class 'Container'
// INFO: (method) Drawable._moveDeltaX( delta:number):void
child._moveDeltaX(delta);
});
}
}
I'm confused about why I am experiencing this issue. In other languages, accessing a protected method like this would work without any problems.