I am writing a function that returns true if the argument passed to it is an instance of the JavaScript Map .
As you might have guessed, typeof new Map() returns the string object , and we don't get the convenient Map.isMap method.
Here is what I still have:
function isMap(v) { return typeof Map !== 'undefined' &&
So far, so good, but when testing cards between frames and when toString() was overridden, isMap fails ( I understand why ).
Example:
<iframe id="testFrame"></iframe> <script> const testWindow = document.querySelector('#testFrame').contentWindow; </script>
Here is the full Pen code demonstrating the problem
Is there a way to write the isMap function isMap that it isMap true when both toString overridden and the map object comes from a different frame?
source share