Do not understand this functional programming, do not understand

const TOKEN = "123"
const ROOT = "//www.baidu.com"

const root = createAPI => (...args) => {
  const result = createAPI(...args)
  return {...result, url: `${ROOT}${result.url}`}
}

const auth = createAPI => (...args) => {
  const result = createAPI(...args)
  return {
    ...result,
    headers: {...result.headers, authorization: `Bearer ${TOKEN}`},
  }
}

const projects = team => {
  return {
    url: `/api/0/teams/${team}/projects/`,
  }
}

root(auth(projects))("fe")
// 
{
   headers: {authorization: "Bearer 123"}
   url: "//www.baidu.com/api/0/teams/fe/projects/"
}

,

-sharp-sharp-sharp 
Apr.09,2021

  • function root accepts a function A and returns a function B . The function body of the function B is:

`<br>const root = function(createAPI){

return function (...args){
    const result = createAPI(...args);
    return {
        ...result,
        url: `${ROOT}${result.url}`;
    }
}

}

`
root accepts one function An and returns another function B. the return result of the
function B is an object, which combines the result of function A
auth.

the final parameter is passed to projects and then the returned objects are combined

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38ef0-2c148.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38ef0-2c148.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?