What is the best way doing cross-realm type checking in JavaScript?

Viewed 67

I'm currently building a type checking library that supports checking variables from another realm (a.k.a. different context).

For basic types like string and number, I can simply use the typeof operator as usual.

For complex types like Date instance, the only way to make it work is to use Object.prototype.toString.call() method. But this method has its problem, I have to iterate through the prototype chain of the instance if the Symbol.toStringTag property was overridden.

The question is, should I iterate through the prototype chain of the instance if the value returned by Object.prototype.toString.call() doesn't match in the first time?

0 Answers
Related