As far as I can tell, there's no way to do forward declaration. JS (ES6) lets you cheat because it's an interpreted, dynamically-typed language. So there's no general solution to your problem, since JS just allows you to do stuff that Godot doesn't.
However, you can solve this particular case by abstracting the factory functionality out of your Status
class into a separate factory class. If you want to support the same syntax, you can then pass the factory to your Status
class's constructor.
class Status:
func _init(factory):
self._factory = factory
func idle():
return self._factory.idle()
class StatusIdle:
extends Status
class StatusFactory:
static func idle():
return StatusIdle.new()
But you can probably just depart a bit from the JS version and use the factory class instead of Status
itself for object initialization.
class Status:
pass
class StatusIdle:
extends Status
class StatusFactory:
static func idle():
return StatusIdle.new()