$ whoami
Erik Wallin
Consultant at DevCode
@c01ac0ca
[0] == 0; //true
[1] == [1]; //false
[1] == "1"; //true...
// In production code, but is more like a quiz
init: function () {
this.constructor.__super__.init.apply(this, arguments);
}
...
...
var args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
// This is a more correct way, still strange.
var args = Array.prototype.slice.call(arguments);
...‘use strict’;
myVar = 4711; // errorDetect errors and potential problems in JavaScript code.
Dangerous constructions (e.g. require ===)
Styling/coding convensions (spaces, indentation, etc)
Should be in a build step
Use it!
Despite ‘use strict’/ESLint
Compare with java
Java8 >> Java7 >~ Java6 >~ Java5 >> Java4
Chrome, Firefox, Safari, IE, mobile
V8, SpiderMonkey, JavaScriptCore (SquirrelFish), Chakra (JScript9)
Different versions of the browsers have different versions of the javascript engines
No control
IT policy (e.g. only Firefox)
Some control
node.js with V8
Full controll
Anyone remembers IE6?
A polyfill is a piece of code that implements the features that you expect the browser to support natively.
Googling for specific parts of ES6
Babel.js - http://babeljs.io/
if (!Array.prototype.find) {
Array.prototype.find = function(predicate) {
// implementation goes here
};
}Transpiler (or source-to-source compiler or transcompiler)
Babel.js - http://babeljs.io/
let quadruples = [1, 2, 3].map(i => i * 4); // ES6
var quadruples = [1, 2, 3].map(function(i) {return i * 4;}); // transpiled ES5Transform back from a minified, concatenated, ES5 file to our original ES6 files
Debug our original files in browser!
The browser downloads source maps when “developer tools” is open
Make sure your build chain produces source maps.
Same principles as ES6 with transpiling
Typescript - http://www.typescriptlang.org/
Coffeescript - http://coffeescript.org/
Closurescript - https://github.com/clojure/clojurescript
Scala.js - http://www.scala-js.org/
Most frameworks/libraries are designed for ES5
Not as many tutorials with ES6
I believe that the framework race will continue and make use of all new features and standardized APIs
Do a presentation at your job
Workshop/discussions in your team
What is good/bad
Code conventions
Start with a small project