This time I will bring you the assignment and Symbol of ES6 objects. What are the precautions for using the assignment and Symbol of ES6 objects? The following is a practical case, let's take a look.
//es6语法允许变量直接为对象的赋值,快捷方便; let liu="呵呵哒"; let long="赖皮哒"; let a={liu,long}; console.log(a) ; //es6语法允许为对象构建key值; let key='skill'; var obj={ [key]:'web'} console.log(obj.skill); //es6语法允许直接合并对象; let s={liuliu:"wowoda",age:20}; let ss={long:"赖皮"}; let sss=Object.assign(s,ss); console.log(sss); //object.is()方法判断是否相等;
type conversion during comparison, while the three equal signs will not. If the type Different, it will return false directly,
and Object.is() is based on the third equal sign, and specially handles NaN, -0, +0, ensuring that -0 and +0 are no longer Same, But it should be noted that Object.is(NaN, NaN) will return true Symbol: As a newdata type was born in es6 : Symbol literally means symbolic, representing the uniqueness of something;
let myId=Symbol(); let myname=Symbol(); console.log (myname) ===>Symbol() typeof myname ===>symbol console.log(myId===myname) ===>false
String; it cannot be operated with other types ;It cannot be converted implicitly;
A Symbol() can be considered as a new function created in memory (so it is not wrong to say that parentheses are the symbol of a function); The Symbol function can also pass in parameters; the parameters are only used as a description of this Symbo;let myId=Symbol("id"); let myname=Symbol("名字");
attribute to ensure uniqueness;
let system=Symbol(); let foo={}; foo[system]="windows"; //还可以保证key值为symbol类型的不被 for in遍历出来; //同样还证明了一点:对象的访问方式,要么以 . ;要么以["这里必须是字符串"];js的底层全部是字符串这种实现; console.log(foo);
let sy=Symbol.for("aaa");
let cccc=Symbol.for("aaa");
Detailed explanation of destructuring assignment in ES6
Detailed explanation of scope and declaration of variables in ES6
The above is the detailed content of ES6 object assignment and Symbol. For more information, please follow other related articles on the PHP Chinese website!