[英]JavaScript Map - setting nested properties
I have this Map 我有这张地图
let map = new Map(Object.entries({
a: 1,
b: {
c: 2,
method() {console.log('test')}
}
}
));
Now, I want to change map.b.method. 现在,我想更改map.b.method。 How can I achieve that?
我该如何实现?
It's just an object stored inside the map. 它只是存储在地图中的一个对象。 Get a reference to it and modify it as you'd like.
获取对其的引用并根据需要对其进行修改。
let map = new Map(Object.entries({ a: 1, b: { c: 2, method() { console.log('test') } } })); map.set('b', { ...map.get('b'), method: function() { console.log('It works ;)'); } }); map.get('b').method();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.