Last active
January 3, 2018 14:07
-
-
Save SalathielGenese/4831f5edf4bdd30d7812b249081bd9e2 to your computer and use it in GitHub Desktop.
JS : multiple symbols as property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'APPLICATION' in Symbol || Reflect.set(Symbol, 'APPLICATION', { configurable: false, enumerable: false, value: Symbol(`APPLICATION#${+new Date}`) }); | |
'COMPONENTS' in Symbol || Reflect.set(Symbol, 'COMPONENTS', { configurable: false, enumerable: false, value: Symbol(`COMPONENTS#${+new Date}`) }); | |
'COMPONENT' in Symbol || Reflect.set(Symbol, 'COMPONENT', { configurable: false, enumerable: false, value: Symbol(`COMPONENT#${+new Date}`) }); | |
class A { | |
get [Symbol.COMPONENTS]() { | |
return 'ALL'; | |
} | |
get [Symbol.COMPONENT]() { | |
return 'ONE'; | |
} | |
} | |
let a = new A(); | |
console.log(Symbol.COMPONENT === Symbol.COMPONENTS); | |
console.log(a[Symbol.COMPONENTS], a[Symbol.COMPONENT]); | |
let b = { | |
[Symbol.COMPONENTS]: 'ALL', | |
[Symbol.COMPONENT]: 'ONE', | |
}; | |
console.log(b[Symbol.COMPONENTS], b[Symbol.COMPONENT]); | |
let c = {}; | |
c[Symbol.COMPONENTS] = 'ALL'; | |
c[Symbol.COMPONENT] = 'ONE'; | |
console.log(c[Symbol.COMPONENTS], c[Symbol.COMPONENT]); | |
// | |
// | |
// The Outputs | |
// | |
// false | |
// ONE ONE | |
// ONE ONE | |
// ONE ONE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScrip version