ECMAScript 6

Currently Firefox only.

by Mark

JavaScript

var a = ['zero', 'one', 'two'];

console.clear();

(() => console.log('IIFE Arrow Inline'))();

((win, doc) => {
    win.console.log('IIFE Arrow Block');
})(this, document);

a.forEach(n => console.log(n));// Arrow Inline

var fn = () => console.log("fn");
fn();    // Logs 'fn'

var o = {
    _name: 'foo',
    //fn,    // This doesn't work [1]
    square: n => n * n,
    printName: () => { console.log(this._name); },        // this refers to window [2]
    printName2: function () { console.log(this._name); }  // this refers to o
};
console.log(o.square(2)); // Logs '4'
o.printName();            // Logs 'undefined'
o.printName2();           // Logs 'foo'

// [1]: http://ariya.ofilabs.com/2013/02/es6-and-object-literal-property-value-shorthand.html
// [2]: The declaration works but the 'this' syntax is to window and not the object literal