WeakSet和Set类似,同样是元素不重复的集合,它们的区别是WeakSet内的元素必须是对象,不能是其它类型。
特性:
1.元素必须是对象。
添加一个number类型的元素。
const ws = new WeakSet()
ws.add(1)
结果是报类型错误。
TypeError: Invalid value used in weak set
添加一个对象。
const ws = new WeakSet()
var a = {p1:'1', p2:'2'}
ws.add(a)
co
C/C++中的volatile关键字和const对应,用来修饰变量,用于告诉编译器该变量值是不稳定的,可能被更改。使用volatile注意事项:
(1). 编译器会对带有volatile关键字的变量禁用优化(A volatile specifier is a hint to a compiler that an object may change its value in ways not specified by the language so that aggressive optimiza