About Haxe and jQuery

You can't say JavaScript and NOT mention jQuery.

How will that work with Haxe?

Using the jQuery classes

There is some difference between how you use jQuery and the jQuery extern.

For a typical JS starting point with jQuery, you write:

    //do your magic

If you don't know, its a short-hand that bind your magic codes to the document ready event, same as you write:

    //do your magic

Both will result in Unknown identifier : $

Haxe does not allow using $ as a class name or a function name, but $ is just a short-hand to jQuery. Yet Haxe requires all class names start with capital letter, so it is JQuery not jQuery. You start your Haxe/JS codes using the jQuery extern as following:

import js.jquery.JQuery;

class Main {
    static public function main():Void {
        new JQuery(function():Void { // when document is ready
            // your magic

It seems to be a few lines more than JS. But you already know, the extra lines are the same for all other haxe targets, it's how Haxe program starts. The main point is new JQuery(...) which is the same as $(...) in JS.

Using jQuery in Haxe

This tutorial is based upon the first post from Andi about jQueryExterns: http://blog.onthewings.net/2010/08/03/using-jquery-in-haxe/

results matching ""

    No results matching ""