Javascript Es2015中的Curly Brakets
我在看一些推特,突然发现 语法把我弄糊涂了Javascript Es2015中的Curly Brakets,javascript,ecmascript-6,brackets,Javascript,Ecmascript 6,Brackets,我在看一些推特,突然发现 语法把我弄糊涂了 const Font = ({ children }) => <Block... const Font=({children})=> 这是一种解构绑定模式。它表示参数children应绑定到传递给函数的对象的children属性的值 在ES2015环境中尝试以下操作: function x({ foo }) { console.log(foo); } x({ hello: "world", foo: "bar", well: "
const Font = ({ children }) =>
<Block...
const Font=({children})=>
这是一种解构绑定模式。它表示参数children
应绑定到传递给函数的对象的children
属性的值
在ES2015环境中尝试以下操作:
function x({ foo }) {
console.log(foo);
}
x({ hello: "world", foo: "bar", well: "that's all"});
字符串“bar”将被记录到控制台,因为这是传递给函数的对象的“foo”属性的值
如果传递给函数的值是一个没有“children”属性的对象,或者如果它根本不是一个对象,那么参数将是未定义的
似乎有一半新的快捷方式看起来像语法错误。。。