Új hozzászólás Aktív témák

  • Jim-Y

    veterán

    válasz Jim-Y #4802 üzenetére

    Például ha Reactos projekte van az embernek, és használ JSX-et és reactify-al buildeli, akkor ezeket a harmony feature-öket használhatja:

    reactify transform also can compile a limited set of es6 syntax constructs into es5. Supported features are arrow functions, rest params, templates, object short notation and classes. You can activate this via --es6 or --harmony boolean option:

    Mozillában tesztelve, próbáldd ki őket, scratchpadben mindegyik megy :)

    arrow functions
    ============

    document.body.addEventListener('click', event => console.log(event.target));

    rest params
    =========

    function sum(a, b, ...rest) {
    return Math.max(...[a,b].concat(rest));
    }

    console.log(sum(1,2)); // 2
    console.log(sum(1,2,4,1,5,6,12,2,3)); // 12

    templates
    ========

    console.log(
    `The max out of 1 and 2 is ${sum(1,2)}`
    );
    // "The max out of 1 and 2 is 2"

    object shorthand notation
    ===================

    var myModule = function() {

    var newMax = function(a, b, ...rest) {
    return Math.max(...[a,b].concat(rest));
    };

    var oldMax = function() {
    return Math.max.apply(Math.max, [].slice.call(arguments));
    };

    // old syntax
    // return {
    // oldMax: oldMax,
    // newMax: newMax
    // };

    return {
    oldMax,
    newMax
    };
    };

    console.log(
    myModule().oldMax(1,2,3,4,9,3,4,5)
    ); // 9

    classes
    ======

    // In iojs/node
    class Topic extends EventEmitter {

    constructor() {
    super();
    }

    publish() {
    this.emit('article');
    }

    subscribe(subscriber) {
    // subscribe
    }

    }

    És nincs felsorolva, de a destructuring is műküdik:

    destructuring
    ==========

    var React = require('react'),
    { Route, DefaultRoute } = require('react-router'),
    { AppComponent, Contact, Content } = require('./components/Screens'),
    baseUrl = require('../appConfig.json').app.baseUrl;

    module.exports = (
    <Route name="home" path={baseUrl} handler={AppComponent}>
    <Route name="contact" path="contact" handler={Contact} />
    <DefaultRoute handler={Content} />
    </Route>
    );

Új hozzászólás Aktív témák

Hirdetés