"what is the motivation for bringing symbols to es6?" Code Answer

5

the original motivation for introducing symbols to javascript was to enable private properties.

unfortunately, they ended up being severely downgraded. they are no longer private, since you can find them via reflection, for example, using object.getownpropertysymbols or proxies.

they are now known as unique symbols and their only intended use is to avoid name clashes between properties. for example, ecmascript itself can now introduce extension hooks via certain methods that you can put on objects (e.g. to define their iteration protocol) without risking them to clash with user names.

whether that is strong enough a motivation to add symbols to the language is debatable.

By andzep on February 10 2022

Answers related to “what is the motivation for bringing symbols to es6?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.