Here is a brief test on using JavaScript Symbols as object keys for an object to achieve information hiding and stay compatible with other code that uses that object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Welcome to Node.js v14.15.4.
Type ".help" for more information.
> let a = Symbol("a")
undefined
> b = {}
{}
> b.a = a
Symbol(a)
> b
{ a: Symbol(a) }
> JSON.stringify(b)
'{}'
> Object.getOwnPropertyNames(b)
[ 'a' ]
> Object.getOwnPropertySymbols(b)
[]
> b[Symbol("c")] = "c"
'c'
> b
{ a: Symbol(a), [Symbol(c)]: 'c' }
> Object.getOwnPropertySymbols(b)
[ Symbol(c) ]
> Object.getOwnPropertyNames(b)
[ 'a' ]
> JSON.stringify(b)
'{}'
> b.hasOwnProperty("a")
true
> b.hasOwnProperty(Symbol("c"))
false
> b[Symbol("c")]
undefined
> b[Symbol(c)]
> b[Object.getOwnPropertySymbols(b)[0]]
'c'
> b[Object.getOwnPropertySymbols(b)[0]]
'c'

In a daily senario, Object.keys() and Object.getOwnPropertyNames() won’t access the Symbol keys in an object. getOwnPropertySymbols() is used to reveal those keys.

It is common to register Symbols in a global registry by using Symbol.for(). In that way, the symbol created with a given string name can be easily retrieved. Otherwise, techniques such as finding through all the symbols with Object.getOwnPropertySymbols() and Reflect may be used.

For further exploration, please navigate to the offical MDN documentaton.

Comment and share

The following are the main technologies used and features supported by this
site:

  • Blog System
    • Hexo
      • Tranquilpeak
    • Node.js
  • Deployment
    • Debian 9.x
    • Git
  • Web Server
    • Nginx,1.15.x
  • Third-Party Services
    • Google Analytics
    • Disqus

The full story of building will be up soon. Stay tuned.

Comment and share

Git

  • A version-control software
  • Allow Multiple People Collaboration by having a Centralized Repository
    • Each user has a copy of the repo
    • Pull from Central repo
    • Local changes push to central repo
    • Group member reviews conflicts to Merge
    • Branch Feature

API

  • Features in the form of pre-defined functions
  • How the internal code works is unavailable

Shell

  • an UI that executes commands/executables and display information in order for users to interact with OS

Comment and share

  • page 1 of 1

Yunqi Shen

I’m a recent graduate majored in CE in Rutgers University. I contribute to open source projects, and build personal projects. I’m a team player. I break asymmetries of information. I’m familiar with C/C++, Java, Python, and Shell Scripting. I’m passinate about exploring Machine Learn ing, Computer Vision, IoT, Blockchain, and Web & Mobile Development. During my last internship, I maintained a Building Automation System, analyzed corresponding data, and led a group of electricians and maintenance engineers.


Site Engineer intern at Lenovo


Herndon, VA