What's the point of es6 double-arrow function calls?

let getters = {
    total: (state) => (symbol) => {
        return (symbol || "$") + state.count;
    }
}
When I saw such a piece of code on the

, I didn"t understand why the arrow function was followed by an arrow function. At first, I thought it was a special way for an arrow function to pass two parameters. I tried to find

.
getters.total(state, symbol)  // 
getters.total(state)(symbol)  //

I don"t know what"s the mystery of writing like this?

Jun.03,2021

this code is equivalent to:

let getters = {
    total: function(state) {
         return function(symbol) => {
            return (symbol || '$') + state.count;
        }
    }
}

as to why you write this, you need to know a concept: function Corey

if you don't know the Corialization of a function, you can define it as:

.
let getters = {
    total: (state, symbol) => {
        return (symbol || '$') + state.count;
    }
}

to fully understand the benefits of function Corialization, you may also need to learn functional programming

.
let getters = {
    total: (state) => (symbol) => {
        return (symbol || '$') + state.count;
    }
}

is actually

.
let getters = {
    total: (state) => {
        return (symbol) => {
                    return (symbol || '$') + state.count;
                }
    }
}

the first argument is that the function of state returns a function (that is, the function whose argument is symbol), so you can call the
arrow function successfully. If you don't write {}, you can omit the return keyword, and default to return the next thing

.

let after1 = {
getter:function (state) {

  return function (symbol) {
      return (symbol || "$") + state.count;
  }

}
};


the double arrow function itself does not have context. This points to the context. in which it is defined

Menu