> Its syntax largely follows the ECMAScript standard, but deviates where necessary.
Anyone can tl;dr the main differences to JS?
> Its syntax largely follows the ECMAScript standard, but deviates where necessary.
Anyone can tl;dr the main differences to JS?
There's always the Cookbook (http://code.haxe.org/category/beginner/index.html) if you want to see for yourself.
block level scoping (vs. function level scoping)
classic inheritance (vs. prototypes)
distinction between hash and object (vs. nope)
required semicolons (vs. still uncertain on that after 10 years)
There's also the whole raft of static typing features, but there's too many of those to mention.Prototypical "inheritance" allows different types of values to be assigned to the same symbol.
E.g. if you have a method bob() on a prototype, you can set object.bob = 'astring'; and it isn't an error.
Personally my favorite feature is its abstract types, which allowed me to define a 0-overhead color abstraction the was just a 32 bit RGBA integer everywhere. Stuff like this can have a sizable performance benefit for games by reducing GC pressure.
for(x in 0 ... 5) {
// increment by +1 only
}
More verbose JSON: var t = Json.parse("{ x: 1 }");
var tx = t.x; // just might be undefined
// vs working
var tx2 = Reflect.getProperty(t, "x")
Tricky array sorts: myArr.sort(function(a, b) {
// just might crash
});
// vs stable
haxe.ds.ArraySort.sort(myArr, function(a, b) {
});
More verbose everything: var v1 = 0;
var v2 = 0;
var v3 = 0;
var v4 = function(a, b) {
// also no 'arguments', that's more verbose too
};
Different syntax for familiar libs (if supported): https://github.com/andyli/jQueryExternForHaxe
new JQuery("li").hide(); // $("li").hide()
If you're not targeting JS your HTTP requests are probably going to be synchronous and block the main thread.If your target is only JavaScript / NodeJS you can get a lot of the benefits of Haxe by using TypeScript, with a much larger ecosystem to help you achieve your goals quickly.