I think this might be a little tricky, or it might have been answered already, but I can't find it.
Anyways, I want to know if the variable that was passed in to my function is a Map()
OFC, the typeof
operator would return object for a map.
I was wondering if I should be doing something like the following, would it make sense?
var something = new Map()
console.log(something.constructor.prototype.toString())
console.log(Map.prototype.toString())
console.log(something.constructor.prototype.toString() === Map.prototype.toString())
console.log(something.constructor.toString())
console.log(Map.toString())
console.log(something.constructor.toString() === Map.toString())
This means that there are 2 "hacky" ways to know which is the type, but I know this is not correct.
Can anyone come up with a better solution than comparing prototypes?