33 ms·
From Haxe's introduction: > Its syntax largely follows the ECMAScript standard, but deviates where necessary. Anyone can tl;dr the main differences to JS?
by greenspot 10y ago
From Haxe's introduction:
> Its syntax largely follows the ECMAScript standard, but deviates where necessary.
Anyone can tl;dr the main differences to JS?
- PeCaN 10y agoIt's much closer to ActionScript and ES4 than to ES5 or ES6/2015/Next/Harmony/Trickshot.LegitScript/whatever the latest ECMAScript standard is. The main difference is probably decent macro support. There's always the Cookbook (http://code.haxe.org/category/beginner/index.html http://code.haxe.org/category/beginner/index.html) if you want to see for yourself.
- jdonaldson 10y agoOff the top of my head, Haxe has: 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.
- carussell 10y agoES has all of those things except for requiring that a statement ends with a semicolon.
- Widdershin 10y agoI would disagree that ES has classical inheritance. ES6 has syntactic sugar over prototypical inheritance that resembles classical inheritance in other languages, but it's still prototypical under the hood.
- colbyAFTrustedK 10y agoIs there a meaningful ? I.e., what does classical inheritance get you that prototypes-under-the-hood don't? For a programmer using classes, that ES's are implemented using prototypes should be as important has how the JVM works.
- robocat 10y agoClassical inheritance enforces that a method can only be overridden by another method in a subclass. 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.
- colbyAFTrustedK 10y agoThat has more to do with a language opting out of having fixed types than it does with class-based versus prototype-based inheritance.
- yoklov 10y agoStrong static typing with a fairly powerful type system, pattern matching, operator overloading, compile time macros, inline functions, in addition to many others. 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.
- benologist 10y agoBasic for loops: 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.