Javascript 什么时候在回调函数中使用括号?ES6风格

Javascript 什么时候在回调函数中使用括号?ES6风格,javascript,ecmascript-6,callback,functional-programming,Javascript,Ecmascript 6,Callback,Functional Programming,为什么带3个参数的innerBuilder不是返回给billerBuilder的那个?为什么带有param itemPrice的未命名函数变成了newYorkBiller 如果itemPrice是一个未命名的函数,那么当我尝试命名它时,为什么代码不起作用 如果要命名,应将其存储在常量中并返回常量 const billerBuilder = (stateName) => { const innerBuilder = (customShipping, customTax) => {

为什么带3个参数的innerBuilder不是返回给billerBuilder的那个?为什么带有param itemPrice的未命名函数变成了newYorkBiller


如果itemPrice是一个未命名的函数,那么当我尝试命名它时,为什么代码不起作用

如果要命名,应将其存储在常量中并返回常量

const billerBuilder = (stateName) => {
  const innerBuilder = (customShipping, customTax) => {
    return (itemPrice) => (itemPrice * customShipping * customTax);
  }
  const nyShipping = 1.03;
  const nyTax = 1.04;
  const njShipping = 1.05;
  const njTax = 1.06625;
  switch (stateName) {
    case 'NY':
      return innerBuilder(nyTax, nyShipping);
    case 'NJ':
      return innerBuilder(njTax, njShipping);
    default:
      return itemPrice;
  }
}
let newYorkBiller = biller('NY');
newYorkBiller(100);
但我不明白你为什么要给它命名。如果是我,我会把它改成:

const innerBuilder = (customShipping, customTax) => {
    const namedFunc = (itemPrice) => (itemPrice * customShipping * customTax);
    return namedFunc;
  }
这种技术称为
套用


如果你给它命名,它怎么不工作?“如果itemPrice是一个未命名的函数”-你在说哪个
itemPrice
?您的代码中有两个,一个是未命名箭头函数的参数,但第二个(在
default
案例中返回)没有声明。问题的标题与文章正文有什么关系?但要回答这个问题:
stateName
itemPrice
itemPrice*customShipping*customTax
周围的括号确实是不必要的(不是说多余的)…customTax=>{return(itemPrice)…我指的是这里的函数。在ES6命名法中,以itemPrice作为参数的函数未命名。但当我尝试命名它时,它会抛出标志。我只是想知道是否有原因不能命名该函数。例如…customTax)=>funcName=(itemPrice)=>这样。
const innerBuilder = (customShipping, customTax) => (itemPrice) => (itemPrice * customShipping * customTax);