[haXe] best strategy to port an existing js library

Danny Wilson danny at decube.net
Fri Dec 7 18:31:10 CET 2007


On Fri, 07 Dec 2007 18:26:01 +0100, Franco Ponticelli  
<franco.ponticelli at gmail.com> wrote:

> I've tried to add a constructor and it works but the __js__ can be  
> removed
> ... the output is exactly the same in this case.
> Why the someOtherFunctionWhichReturnsSomething function is there?
>

To demonstrate how to wrap a global javascript function, which returns  
something into a class in a typesafe way.
So:

--- JS library ---
function add(x,y){ return x+y; }

-- haxe wrapper --
class AddClass {
   static function __init__() { AddClass.prototype.add = untyped  
__js__("add");

   public function add(x:Int,y:Int):Int {return null;}
   // if I don't return null, haXe compiler will complain

   public function new();
}

new AddClass().add(1,2); // 3




Kind regards,

      Danny Wilson


deCube.net - http://decube.net/
web application design and development




More information about the Haxe mailing list