10.4.4 Extensions

It is common to see Static Extension used with the math library. This code shows a simple example:

class MathStaticExtension {
  /* Converts an angle in radians to degrees */
  inline public static function toDegrees(radians:Float):Float {
    return radians * 180 / Math.PI;
  }
}
using MathStaticExtension;

class Main {
  public static function main() {
    var ang = 1 / 2 * Math.PI;
    trace(ang.toDegrees()); // 90
  }
}