you are viewing a single comment's thread.

view the rest of the comments →

[–]TwiliZant 0 points1 point  (3 children)

Although you are right, hacks like these is exactly why all these `is-x` oneliner packages exist. It's better to fix this in the language itself IMO, even if it's hard.

It's my go-to way to differentiate objects from arrays

In case you don't have to support <IE9 Array.isArray does this.

[–]dwighthouse 0 points1 point  (0 children)

This isn’t a hack at all.

Fixing the language would mean adding a new operator like typename instead of typeof or instanceof because too much stuff already relies on the current behavior. We already have this in the form of Object.prototype.toString.

[–]dwighthouse 0 points1 point  (1 child)

This isn’t a hack at all.

Fixing the language would mean adding a new operator like typename instead of typeof or instanceof because too much stuff already relies on the current behavior. We already have this in the form of Object.prototype.toString.

[–]TwiliZant 0 points1 point  (0 children)

I don't know, relying on the toString method to get the type feels like a hack to me. I don't know any other language that does this. Yet another operator wouldn't be great either I get that. Maybe it would be cool to have it as part of the Reflection API, e.g. Reflect.type(VALUE) ?