Set新方法学习
方法
下面方法中的每个都用于对比检查 Set 与另一个特定 Set 的内容。
语法都是:setA.compareMethod(setB),下面分别用 A、B 指代 setA、setB
intersection(): returns a new set with elements in both this set and the given set.
返回 A 与 B 的交集
union(): returns a new set with all elements in this set and the given set.
返回 A 与 B 的并集
difference(): returns a new set with elements in this set but not in the given set.
返回 A 与 B 的差集,即属于 A 但不属于 B 的集合.
symmetricDifference(): returns a new set with elements in either set, but not in both.
返回 A 与 B 的对称差集,等于并集-交集
isSubsetOf(): returns a boolean indicating if all elements of a set are in a specific set.
返回 A 是否包含于 B,即 B 包含 A
isSupersetOf(): returns a boolean indicating if all elements of a set are in a specific set.
返回 A 是否包含 B
isDisjointFrom(): returns a boolean indicating if this set has no elements in common with a specific set.
返回 A 是否与 B 互斥
兼容性
考虑兼容低版本浏览器,需引入 polyfill