Cannot assign to read only property 'name' of object '[object Object]'

后端 未结 6 1516
攒了一身酷
攒了一身酷 2021-02-04 03:19

The following code will throw an error only for the name property. It could be fixed by specifying name property as writable in Object.create

6条回答
  •  执念已碎
    2021-02-04 04:13

    I ran into this issue in Angular, while setting a local variable from ActivatedRoute's queryParams, and attempting to conditionally either override or merge... Duplicating beforehand did the trick:

    updateQp(qp = {}, force = false) { 
        let qpLoc = Object.assign({}, this.queryParamsLocal)
        this.queryParamsLocal = force ? qp : Object.assign(qpLoc, qp)
    }
    

提交回复
热议问题