为什么这个片段在 Node (10.5)
.then(function() {
this = {...this, ...payload};
this.update();
resolve({ok:true, node});
});
出现以下错误:
ReferenceError: Invalid left-hand side in assignment
有效负载包含一些需要添加到 this
的属性,或者如果属性存在,则需要更新该属性。
我不明白为什么会出现这个错误:(
最佳答案
嗯,错误是直截了当的,它说 Invalid left-hand side in assignment
,这意味着您在赋值的左侧使用了错误的元素。
那是因为您正在编写 this = {...this, ...payload};
,您试图将值写入 this
。在游览功能中,这是错误的,也是不可能的,因为您不能更改 this
并为其分配一个值,因为它在JavaScript。
如果您检查 MDN this Reference你可以看到:
In most cases, the value of
this
is determined by how a function is called. It can't be set by assignment during execution, and it may be different each time the function is called.
关于javascript - 引用错误 : Invalid left-hand side in assignment when really assigning a value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51097728/