Stenway Developer Network

Overriding

Methods and properties can be overridden. They must be declared as overridable:

package MyLib

using Js

class MyBaseClass
  protected _myBackingProperty float set

  overridable myProperty float
    get : return this._myBackingProperty
    set : this._myBackingProperty = value
  end
  
  overridable doSomething()
    Console.log("Hello world")
  end
end

class MyClass extends MyBaseClass
  override myProperty float
    get : return this._myBackingProperty
    set : this._myBackingProperty = 2 * value
  end
  
  override doSomething()
    Console.log("Something else")
  end
end

If a method or property is not declared as overridable, the force override keyword must be used to override it:

package MyLib

using Js

class MyBaseClass
  doSomething()
    Console.log("Hello world")
  end
end

class MyClass extends MyBaseClass
  force override doSomething()
    Console.log("Forced to do something else")
  end
end