Sign in

ES6 export problem

kcstrom edited in Sun, 10 Jul 2022

You can see this structure in many documents

export default DropTarget(types, spec, collect)(MyComponent2);

But I don't quite understand , Looking at the document, I can't find the syntax to describe it

export default OneClass(arg)(arg);

My understanding is that export is an immediate function? It's just like JS's immediate function, but it's not very reasonable, because import is not a variable

5 Replies
commented on Sun, 10 Jul 2022

Normally, it should be

  export default result


export default OneClass(arg)(arg);

The difference lies in oneclass (ARG) (ARG), which is similar to function coriolisation. After accepting multiple parameters, it will eventually return result. From this point of view, the above two export methods are almost the same

commented on Sun, 10 Jul 2022

Export and export default are both output variables. The difference is that export outputs this variable directly. However, the essence of the export default command is to assign the following value to the default variable and then output it. Please refer to the ES6 module Ruan Yifeng

commented on Mon, 11 Jul 2022

Oneclass returns a function, which is a high-order function of functional programming

commented on Mon, 11 Jul 2022

It is equivalent to the following code:

// DropTarget 返回一个函数
var wrapper = DropTarget(types, spec, collect);
// wrapper 返回一个包装后的组件
var result = wrapper(MyComponent2);
// 导出组件
export default result;
commented on Mon, 11 Jul 2022

Higher order functions can be regarded as continuous execution, and then return a new function each time.

let OneClass = (arg1) => {
    // do something;
    return (arg2) => {
        // do something;
        return something;

export default OneClass(arg1)(arg2);
lock This question has been locked and the reply function has been disabled.