Wednesday, June 17, 2015

I saw Kyle Simpson give a talk on wrangling transpilation at Austin JavaScript last night.

This was quite different from the one other transpilation talk I've ever seen, and in some ways in conflict thematically. Kyle was quick to point out that transpilation is an invented word and that he felt academics don't take in serious as it can, yes, mean different things to different people. In collision with the other presentation I've seen he suggested that transpilation is not the act of how-do-I-make-sense-of-things-to-compile-them-as-a-compiler, as one is not casting down a level from a lofty language to a more rudimentary one (as he would define compiling) but instead one is casting from the lofty language to a different shape of the lofty language. In his example ES6 gets cast to ES5 in the name of developers writing in modern JavaScript while being able to render out JavaScript which will be capable of running in most modern browsers which really only support ES5. Babel was suggested to be the best tool for this, and it was suggested that, yes, this is something you should want to do. Just waiting ten years for all of the browsers to support ES6 is not the mature way to solve the problem. It is nearly time to now think of JavaScript are evergreen and versionless given... Babel. While traceur is another tool like Babel, Kyle suggested Babel is really the one player in its space to care about. Different browsers support different features in ES6, with Edge having to date the most support so far, and there is a way to test to see if your browser can hang, but it's NOT like this:

try {
   x = y => y;
   arrows = true;
}
catch (err) {
   arrows = false;
}

 
 

Uncaught SyntaxError: Unexpected token => ...will be shoved up to Google Chrome's console, in this scenario, if the arrow cannot be supported well before the try/catch ever is run because the arrow cannot be compiled, as, yes, browsers are compiling your JavaScript to understand them. The thing to do instead is:

try {
   new Function("x = y => y;");
   arrows = true;
}
catch (err) {
   arrows = false;
}

 
 

es6-shim was offered as a good tool for polyfills for the stuff which is not compatible. Ecma International is to bless ES6 with its approval tomorrow! It's on everyone. The let keyword beckons:

let obj = {
   foo(x) {
      this.x = x;
      setTimeout(() => console.log(this.x), this.x);
   }
};

No comments:

Post a Comment