【发布时间】:2017-03-10 16:24:54
【问题描述】:
我想不出办法,但我想要的是:
<ColumnDef key="label" ...createCommonColumnProps.call(this, {somestuff}) />
<ColumnDef key="count" ...createCommonColumnProps.call(this, {someOtherStuff}) />
<ColumnDef key="value" ...createCommonColumnProps.call(this, {yetOtherstuff}) />
我希望它非常简单,我只是个白痴,但如果不创建变量,我就找不到方法
<ColumnDef key="label" {...column1} />
<ColumnDef key="count" {...column2} />
<ColumnDef key="value" {...column3} />
大约有5个props,其中一些受到传递给函数的对象的影响。
当我在 chrome devtools 控制台中尝试这个(只是 js 部分,而不是 jsx 部分)时,我看到了这样的事情:
> function a() {
return {a:1, b:2}
}
undefined
> y = {... a()}
VM341:1 Uncaught SyntaxError: Unexpected token ...
> x = ... a()
VM368:1 Uncaught SyntaxError: Unexpected token ...
> x = {a:1,b:2}
Object {a: 1, b: 2}
> y = {...x}
VM888:1 Uncaught SyntaxError: Unexpected token ...
【问题讨论】:
-
{...createCommonColumnProps.call(this, {somestuff})}?
标签: javascript reactjs ecmascript-6 jsx spread-syntax