javascript函数参数用大括号传递和不用大括号传递有什么区别?比如下面的代码:
import CheckPermissions from './CheckPermissions';
const Authorized = ({ children, authority, noMatch = null }) => { //大括号括起来和不用大括号有什么区别?
const childrenRender = typeof children === 'undefined' ? null : children;
return CheckPermissions(authority, childrenRender, noMatch);
};
问题就是第2行代码的大括号传参,好像不用大括号也行吧?使用大括号和不使用大括号有什么区别呢?
带大括号是指传递一个参数,参数类型为对象,里面有三个属性children, authority, noMatch,不带大括号就是传递三个参数,这里的大括号不是块级作用域,就是单纯的表示一个对象