、
{ // 声明 let a1 = Symbol(); let a2 = Symbol(); console.log(a1 === a2); //false let a3 = Symbol.for(‘a3‘); let a4 = Symbol.for(‘a3‘); console.log(a3 === a4); //true } { let a1 = Symbol.for(‘abc‘); //当key值 let obj = { [a1]: ‘123‘, ‘abc‘: 345, ‘c‘: 456 }; console.log(‘obj‘, obj); //abc:345,c:456,Symbol(abc):‘123‘ for (let [key, value] of Object.entries(obj)) { // Object.entries方法返回一个数组,成员是参数对象自身的(不含继承的)所有可遍历( enumerable )属性的键值对数组。 // var obj = { foo: ‘bar‘, baz: 42 }; 例如:Object.entries(obj) => [ ["foo", "bar"], ["baz", 42] ] console.log(‘let of‘, key, value, obj); // let of abc 345 {abc:345,c:456,Symbol(abc):"123"};let of c 456,{abc:345,c:456,Symbol(abc):"123"} } Object.getOwnPropertySymbols(obj).forEach(function(item) { console.log(‘111‘,obj[item]); //123 }) Reflect.ownKeys(obj).forEach(function(item) { console.log(‘ownkeys‘, item, obj[item]);//abc 345,c 456,Symbol(abc) 123; }) }
原文:http://www.cnblogs.com/Byme/p/7684468.html