Javascript ECMA双发箭使用?

Javascript ECMA双发箭使用?,javascript,syntax,ecmascript-6,Javascript,Syntax,Ecmascript 6,你能解释一下这个代码吗?是咖喱吗 export const thing = (...items) => (wotsit) => { const thing = (props, {enums}) => { // ... }; thing.contextTypes = { enums: PropTypes.object }; return th

你能解释一下这个代码吗?是咖喱吗

    export const thing = (...items) => (wotsit) => {
        const thing = (props, {enums}) => {
            // ...
        };

        thing.contextTypes = {
            enums: PropTypes.object
        };

        return thing;
    };

    export default thing;

它返回一个稍后调用的函数。如果函数不在ES6中,它看起来会像:

function thing(a, b) {
    return function(wotsit) {
        const thing = {};
        ...
        return thing;
    }
}
最终会有这样的效果:

let a = thing(1, 2);
let b = a(wotsit); // Gives you back thing object
export const thing = function(...items) {

    // `items` will be an array with all the arguments that you pass in.

    return function(wotsit) {
        const thing = function(props, {enums}) {
            // ...
        };

        thing.contextTypes = {
            enums: PropTypes.object
        };

        return thing;
    };
};

export default thing;

它返回一个稍后调用的函数。如果函数不在ES6中,它看起来会像:

function thing(a, b) {
    return function(wotsit) {
        const thing = {};
        ...
        return thing;
    }
}
最终会有这样的效果:

let a = thing(1, 2);
let b = a(wotsit); // Gives you back thing object
export const thing = function(...items) {

    // `items` will be an array with all the arguments that you pass in.

    return function(wotsit) {
        const thing = function(props, {enums}) {
            // ...
        };

        thing.contextTypes = {
            enums: PropTypes.object
        };

        return thing;
    };
};

export default thing;
是的。如果没有,它将如下所示:

let a = thing(1, 2);
let b = a(wotsit); // Gives you back thing object
export const thing = function(...items) {

    // `items` will be an array with all the arguments that you pass in.

    return function(wotsit) {
        const thing = function(props, {enums}) {
            // ...
        };

        thing.contextTypes = {
            enums: PropTypes.object
        };

        return thing;
    };
};

export default thing;
另一方面,这:

const thing = (props, {enums}) => {
    // ...
};
正在使用参数。与此相同:

const thing = (props, options) => {
    let enums = options.enums;
};
是的。如果没有,它将如下所示:

let a = thing(1, 2);
let b = a(wotsit); // Gives you back thing object
export const thing = function(...items) {

    // `items` will be an array with all the arguments that you pass in.

    return function(wotsit) {
        const thing = function(props, {enums}) {
            // ...
        };

        thing.contextTypes = {
            enums: PropTypes.object
        };

        return thing;
    };
};

export default thing;
另一方面,这:

const thing = (props, {enums}) => {
    // ...
};
正在使用参数。与此相同:

const thing = (props, options) => {
    let enums = options.enums;
};

=>lambda用于匿名函数,export用于导出函数,其他文件可以导入的变量=>lambda用于匿名函数,export用于导出函数,其他文件可以导入的变量我们不应该在这里使用bind,因为您在代码中没有使用胖箭头?只要您在这些函数中使用它。看到了吧,我想是隐式返回让我大吃一惊——这么多ECMA都具备了1990年代早期Perl代码的易读性。Perl社区实现了隐式返回和许多其他社会上不可接受的东西,我希望ECMA PEEP很快也会这样做。谢谢您的帮助。我们不应该在这里使用bind吗,因为您的代码中没有使用胖箭头?只要您在这些函数中使用它就可以了。看到了吧,我想是隐式返回让我大吃一惊——这么多ECMA都具备了1990年代早期Perl代码的易读性。Perl社区实现了隐式返回和许多其他社会上不可接受的东西,我希望ECMA PEEP很快也会这样做。谢谢你的帮助。