javascript - react : how do you assign default properties of object props?

标签 javascript reactjs

例如,子组件被传递 position={{x: 50}}。如何将子组件内的 this.props.position 重新分配为等于 {{x: 50, y: 0}}

最佳答案

看起来您正在使用 React;如果您还使用 ES2016,您将能够使用 Object.assign:

var initial = {x: 0, y: 0};
var passed = {x: 50};

var result = Object.assign({}, initial, passed);

console.log(result); // { x: 50, y: 0 }

关于javascript - react : how do you assign default properties of object props?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40470752/

相关文章:

reactjs - BrowserRouter Link 重写 onClick 事件

javascript - 如何将 Prop 从父级传递给子级再到子级的子级?

javascript - 获取印度当前时间和日期

javascript - React 加载 Spinner + Redux?

javascript - 大括号内的 JSX

javascript - 在 ngx-editor 中,单击按钮时如何在光标位置插入 html block

javascript - 使用沙箱从 Chrome 应用程序发出 ajax 请求

javascript - 正则表达式替换指令中的 html 标签

javascript - 即使在向滚动条附加内容时也将滚动条固定在底部

javascript - 产品库 - 该网站如何为每种可能的组合生成图像