es6 Symbol

let s = Symbol()
console.log(typeof s)

let foo = Symbol('foo')
let bar = Symbol('bar')
console.log(foo);
console.log(bar);

console.log(foo === bar)  //false
let foo2 = Symbol('foo');
console.log(foo.toString() == foo2.toString())

 

//用法
const a = {}
const mySymbol = Symbol()
a[mySymbol] = 'hello'
console.log(a[mySymbol])

 

posted on 2017-05-12 18:39  宝清老窖  阅读(95)  评论(0编辑  收藏  举报