Curly Brakets in Es2015 [duplicate]

孤街醉人 提交于 2019-12-05 12:58:06

It's a destructuring binding pattern. It indicates that the parameter children should be bound to the value of the children property of an object passed to the function.

Try this in an ES2015 environment:

function x({ foo }) {
  console.log(foo);
}

x({ hello: "world", foo: "bar", well: "that's all"});

The string "bar" will be logged to the console, because that's the value of the "foo" property of the object passed to the function.

If the value passed to the function is an object with no "children" property, of if it's not an object at all, then the parameter will be undefined.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!