2020-07-20 JS Symbol SymbolSymbol.species用于控制生成新实例时,类的内置方法使用哪个构造器 Symbol.iterator用于生成对象的迭代器 123456789101112131415161718192021222324var a = { 1: "张三", 2: "12"}a[Symbol.iterator] = function() { index = 0; return { next: ()=>{ index++; return { value: this[index], done: !this[index] } } }}for (var i of a) { console.log(i) //张三 //12} Symbol.toPrimitive在做类型转换时,将对象转为原生类型值 12345678910111213var arr = [1, 2, 3, 4]console.log(arr + 10)// 1,2,3,410arr[Symbol.toPrimitive] = function(hint) { if (hint === "default" || hint === "number") { return this.reduce((acc,curr)=>acc + curr, 0) }}console.log(arr + 10)//20 Symbool Newer JS Proxy Older JS Promise