What is the difference between ImmutableJS Map() and fromJS()?

前端 未结 2 1151
悲哀的现实
悲哀的现实 2021-01-30 16:59
var a = {address: {postcode: 5085}}

var b = Immutable.fromJS(a)
var c = b.setIn([\'address\', \'suburb\'], \'broadview\').toJS(); // no error
console.log(c); 

var d =          


        
2条回答
  •  时光取名叫无心
    2021-01-30 17:19

    fromJS does a deep conversion. That is, it'll recurse through all the keys and convert all elements to Lists, Maps, etc.

    In your second example, address is a plain object, not an ImmutableJS object, so you cannot use setIn to change its value.

提交回复
热议问题