We use symbols to make object properties or methods private. Therefore, we hide the details and show only the most necessary. This is called abstraction.
How to implement this: Let's create a simple class with the radius property.
class Circle { constructor(radius) { this.radius = radius; } }
A character is essentially a unique identifier. Each time we call this function, we get a unique identifier. However, this is not a constructor function.
Symbol()===Symbol()
Implementation:
const _radius=Symbol() class Circle { constructor(radius) { this[_radius] = radius;
Now check this out. Create an instance of Circle:
const c=new Circle; console.log(Object.getOwnPropertyNames(c))
source share