How To Hack JavaScript With Well-Known Symbols (5 Ways)
They call them well-known symbols — even though most developers have never used them or even heard of them.
A really cool feature you can use to make magic like this happen:
You’ll see how we built these classes with well-known symbols to do this.
They’re all about completely customizing the normal behavior of built-in operations like for..of
. It's like operator overloading in C++ and C#.
Also all static methods of the Symbol
class.
1. Symbol.hasInstance
So first up we have Symbol.hasInstance
: for easily changing how the instanceof
operator behaves.
Normally instanceof
is all about checking if a variable is an instance of class.