ES6-Symbol的用法 ,symbol在对象中的应用,改变值
程序员文章站
2022-08-02 16:19:01
ES6-Symbol的用法 ,symbol在对象中的应用,改变值 ......
es6-symbol的用法,,symbol在对象中的应用,改变值
let a = new string; let b = new number; let c = new boolean; let d = new array; let e = new object; //symbol //声明symbol //symbol类型是一个全局的原始类型 let f = symbol(); console.log(typeof(f)) //symbol let g = symbol('ananiah'); console.log(g) //symbol(ananiah) console.log(g.tostring()) //symbol(ananiah) 转为字符串 //symbol在对象中的应用 let ananiah = symbol(); let obj = { [ananiah] : '大诶啊' } console.log(obj[ananiah]) //大诶啊 //改变值 obj[ananiah] = 'web'; console.log(obj[ananiah]) //web // 用法 let noage = {name:'ananiah',skill:'eat'}; let age = symbol(); noage[age] = 18; console.log(noage) // {name: "ananiah", skill: "eat", symbol(): 18} for(let item in noage){ console.log(noage[item]) //ananiah eat } console.log(noage[age]) // 18
上一篇: 一个说实话的女孩