Module-level fields are here! - Haxe - The Cross-platform Toolkit

Read more on our blog:

10 Likes

Wow! This is awesome, and also seems like a big deal. :slight_smile: I remember when I first saw Haxe hello-world with everything in classes and reflexively thought, “oh, like Java”.

Would be great to showcase module-level fields in the “A Taste of Haxe” code block on the front page of <haxe.org>.

@uvtc I think that will have to wait until Haxe 4.2 is officially released, but yes, agreed.

Are there any plans for module level variables?

Oh, the example there shows a final, but not a var. I assume that module-level vars are supported as well (since “fields” means both functions and variables).

Oops, somewhy my brain replaced ‘fields’ with ‘functions’ while reading and I didn’t even notice the final there.

I’m really happy about this feature :slight_smile:

it’s would be better if support inline for main()

inline function main()

@Zhan I’m not really sure what the point of that would be.

import global.cc.Component;

import global.cc.Label;

var label:Label;

var text:String;

function onPreLoad() {

    trace('onpreload');

}

function onLoad() {

    trace(js.Lib.nativeThis);

    label = cast js.Lib.nativeThis.label;

    text = cast js.Lib.nativeThis.text;

    label.string = text;

}

function update() {}

function onDisable() {}

function main() {// I hope support inline here

    global.Cc.Class({

        name: "fuck",

        'extends': Component,

        properties: {

            label: {

                'default': null,

                type: Label

            },

            // defaults, set visually when attaching this script to the Canvas

            text: text

        },

        onLoad: onLoad,

        update: update,

        onDisable: onDisable

    });

}

and target js is

function Main_main() {

    cc.Class({ name : "fuck", "extends" : cc.Component, properties : { label : Main_label, text : Main_text}, onLoad : Main_onLoad, update : Main_update, onDisable : Main_onDisable});

}

and what I want is only

cc.Class({ name : "fuck", "extends" : cc.Component, properties : { label : Main_label, text : Main_text}, onLoad : Main_onLoad, update : Main_update, onDisable : Main_onDisable});

instead of

function Main_main() {

    cc.Class({ name : "fuck", "extends" : cc.Component, properties : { label : Main_label, text : Main_text}, onLoad : Main_onLoad, update : Main_update, onDisable : Main_onDisable});

}

//BTW, how to get “this” keyword of module?