let s = Symbol();
let name = Symbol('name'); // 创建一个Symbol的值 let obj = { [name]: 'zhangsan', // 将Symbol的值作为对象的属性(key) } console.log(obj[name]); // zhangsan
let obj = { [Symbol('name')]: 'zhangsan', // 这个值永远无法拿到 } console.log(obj[Symbol('name')]); // undefined
let name = Symbol('name'); let obj = { [name]: 'zhangsan', age: 66 } for (let key in obj) { console.log(obj[key]); // 66 }
console.log(Object.keys(obj)); // ['age']
let name = Symbol('name'); let obj = { [name]: 'zhangsan', age: 66 } console.log(Object.getOwnPropertySymbols(obj)); // [ Symbol(name) ]