miercuri, 18 octombrie 2017

Weird new JavaScript syntax? It's called ES6

Weird new JavaScript syntax?

ECMAScript6 (or ES6 for short) is "a kind of JavaScript" that does not run in the old browsers. It is the modern version of the well-kown ECMAScript (commercially known as JavaScript) and it is heavy inspired from TypeScript.

https://engineering.carsguide.com.au/es5-vs-es6-syntax-6c8350fa6998


The first example is from Polymer Project: https://www.polymer-project.org/2.0/start/quick-tour

class CustomElement extends Polymer.Element {
    static get is() { return "custom-element"; }
    constructor() {
        super();
        this.textContent = "I'm a custom-element.";
      }
  }

Right, ES6 classes are available in Chrome 42+ (starting with 2015-04-14)
Documentation: https://googlechrome.github.io/samples/classes-es6/

The second example is from Ionic Framework: https://ionicframework.com/docs/components/#action-sheets

import { ActionSheetController } from 'ionic-angular'; export class MyPage { constructor(public actionSheetCtrl: ActionSheetController) { }
...

Imports and exports are part of ES6 Modules Final Proposal

Recommended book (online): Exploring ES6