Just like the title, there are two examples (you can imagine other examples by yourself):
// 替换的例子
let a = {'a': 123, 'b': 234, 'c': 345}
let tmp = {'a': 'qwe'}
a = {...a, tmp}
// 删除再添加的例子
let a = {'a': 123, 'b': 234, 'c': 345}
let tmp = {'a': 'qwe'}
delete a.a
a = {...a, tmp}
Who is more efficient?
为情所困2017-06-12 09:30:17
Delete is not to mention slow, the key is that it does not directly release memory (MDN document mentioned this at the beginning). So replace it directly in your situation without thinking too much.
So what is the use of delete?
Currently, all I can think of is that it is available under inheritance. For example, there is attribute a on the prototype chain of an object, and it also defines attribute a. Then for some reason, it no longer needs its own attribute a, and only needs to use the attribute a on the prototype chain... Then delete this attribute. Lose. But even with this application, it is difficult to encounter actual application scenarios.
仅有的幸福2017-06-12 09:30:17
It’s definitely the first kind of speed.
delete a.a
is a performance killer.
I mentioned it in the lecture "Front-end programmers should know some V8 knowledge".