例如,子组件被传递 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/