主要实现的方法
add(value):向集合添加一个新的项。
remove(value):从集合移除一个值。
has(value):如果值在集合中,返回true,否则返回false。
clear():移除集合中的所有项。
size():返回集合所包含元素的数量。与数组的length属性类似。
values():返回一个包含集合中所有值的数组。
has(value)方法
this.has = function(value){
return items.hasOwnProperty(value);
};
add方法
|
|
remove和clear方法
|
|
size方法
|
|
values方法
|
|
参考资料 《学习JavaScript数据结构与算法》