标签:let array bsp ring eof nod boolean div es6
//Symbol多用于node.js let a=new String; let b=new Number; let c=new Boolean; let d=new Array; let e=new Object; //上面这些new出来的类型都是对象 let f=Symbol(); //打印出来的f是symbol类型(在控制台显示为红色) console.log(typeof (f)); //对对象元素的保护 let nl=Symbol(); let obj={ [nl]:‘宁静‘ } console.log(obj[nl]); obj[nl]=‘web‘; console.log(obj[nl]); //不保护 let obj1={name:‘nl‘,skill:‘web‘}; let age=Symbol(); obj[age]=18; console.log(obj[age]); // for(let item in obj1){ //这个循环输出对age进行了保护 // console.log(obj[item]); // } //要打印出年龄,见下面 console.log(obj[age]);
标签:let array bsp ring eof nod boolean div es6
原文地址:https://www.cnblogs.com/NeryXJ/p/9648258.html