ECMAScript 6 入门之新的数据类型Symbol

1、Symbol,一个每次创建都不一样的值

Symbol
undefined
null
Boolean
String
Number
Object
let c=Symbol("这是一个Symbol");
let a=Symbol();
let b=Symbol();
console.log("a:",a);
console.log("b:",b);
console.log("c:",c);
console.log(a===b);

let name=Symbol();
{
    var person={};
    person[name]="file1";
}

{
    person["name"]="file2";
}
console.log("person:",person);

 2、防止重写上游的值

let name=Symbol();
{
    var person={};
    person[name]="file1";
    console.log("person[name]:",person[name]);
}

{
    let name=Symbol();
    person[name]="file2";
    console.log("person[name]:",person[name]);
console.log("person[name]:",person[name]);

} console.log("person[name]:",person[name]);

 

posted @ 2017-04-23 21:41  HongMaJu  阅读(347)  评论(0编辑  收藏  举报