var npm = require("npm")
var immutable = require("immutable");
var test = immutable.fromJS
const a = test({name:true,b:[]})
console.log(a);
a.set('name',false);
console.log("------------");
console.log(a.get('name')) // gives still value true.
最后一个控制台的期望值是多少?我认为这是真的。有人可以帮助我哪里出错了
最佳答案
Immutable.js 的要点是您从中获取的对象是不可变的(无法更改)。看起来像增变器操作的操作返回一个新对象。所以:
a = a.set('name', false);
来自 the documentation :
set()
Returns a new Map also containing the new key, value pair. If an equivalent key already exists in this Map, it will be replaced.
(我的重点)
关于javascript - 无法更新 Set 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54652484/