gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 16:22:41 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com