When I was reading the vue source code today, I encountered a writing method that I didn't understand.
view source
const deduped = [...new Set(pendingPostFlushCbs)]
在我看来,它是数组的浅显副本.但为什么我要先转换成SET,我能有更好的表现吗?我该怎么理解它呢?
When I was reading the vue source code today, I encountered a writing method that I didn't understand.
view source
const deduped = [...new Set(pendingPostFlushCbs)]
在我看来,它是数组的浅显副本.但为什么我要先转换成SET,我能有更好的表现吗?我该怎么理解它呢?
对于Set,您可以删除重复项:
pendingPostFlushCbs = [1,2,5,5,6,8,8,]
const deduped = [...new Set(pendingPostFlushCbs)]
const deduped1 = [...pendingPostFlushCbs]
console.log(deduped)
console.log(deduped1)