lukeed/klona

Classes named "Object"

fabiosantoscode opened this issue · 1 comments

I noticed the usage of Object.prototype.toString and it seemed really interesting, but custom classes can be mistaken as other objects inadvertently through this method.

> Object.prototype.toString.call(new (class Object {}))
'[object Object]'

I’m fine with that. It’s very common throughout js packages. Fastest way to check for multiple instance types. And in the age of TS, it’s especially uncommon to have a custom Object class cuz you’ll have a bunch of uncompliance errors.

You can also spoof another way — even more uncommon imo. Just as you can spoof instanceof Object checks.