Which means you can only.

Gentleman: So, just use that package :-

Mcnicoll: S34n: why do you want to know if something is a regular expression, though?

Yoshihara: S34n: most likely you’re just calling .test on it. It’s best to just check if something has a .test method

Reineck: Gentleman: what scenarios would make that an unreliable check?

Badenoch: That way you also let people p*** things that have a .test method but isn’t a RegExp object, allowing them to have more useful behaviour in their .test if they need to

Gentleman: Zomg: instanceof doesn’t work across iframes, or if the “constructor” property has been modified

Reineck: Hylle: if it was all of them, then it wouldn’t work at all.

Osso: Zomg: a instanceof b is literally bSymbol.hasInstancea

Reineck: Gentleman: so seems again like a thing that would be a thing only if someone is doing something dumb 😛

Patao: You can change Symbol.hasInstance for anything. And then there’s code realms

Reineck: This goes back to the whole “wrap everything in an IIFE in case someone redeclares undefined”

Reineck: Which is not really a thing but it could be!

Barnwell: Zomg: no, you can actually get objects from different code realms interacting between each other. And it *should* work.

Gentleman: Zomg: it’s javascript. everybody is doing *something* dumb.

Brandi: The “doing something dumb” here would be checking instanceof, which makes it not work 😛

Reineck: Someone suddenly breaking the instanceof check by redefining constructor seems about equally likely as someone breaking your library

Fiume: Zomg: again, code realms.

Berver: Zomg: http://www.ecma-international.org/ecma-262/6.0/#sec-code-realms

Reineck: So how does this actually affect things?

Gentleman: If something comes from an iframe and you want to check it

Gentleman: Or in node, from the “vm” module

Gentleman: Which is not “something dumb” as much as its “something that should still work”

Koncan: But now it breaks because you’re using instanceof

Reineck: You should just say that instead of random things like CODE REALMS

Gentleman: That’s what it’s called in the spec

Gentleman: It’s not a random thing, it’s the proper name.

Reineck: First time I heard of it

Gentleman: That’s more on you than us :-p

Vermeulen: People keep saying not to use instanceof b/c of iframes, but honestly, how often are you really transferring objects across realms and typechecking them

Reineck: STRML: we actually have some stuff with iframes that could in theory have that issue, but we don’t do that sorta typechecking anyway

Mellor: As JS environments try to give you more possibilities of isolating/sandboxing code, you’re soon going to have lots of realms interacting with each other.

Gentleman: STRML: you might need to refactor to iframes for PCI compliance for payments stuff and if you use instanceof, it would break

Gentleman: STRML: so, pretty often, since everyone working with money likely needs to do that eventually

Czyrnik: Well. depends so much on your applications.

Raguso: STRML: iframes aren’t the only thing that have a different Realm of execution :

Biffle: In any case, Object.prototype.toString.call is my general goto. aka _.isRegExp

Gentleman: STRML: right but Object#toString is unreliable in ES6.

Kiefel: STRML: that breaks in ES6 too

Pensinger: Really, that’s changed?

Gentleman: And my is-regexp module is more robust than _.isRegExp, which is why i made it.

Ebbert: STRML: you can now change the Cl*** of anything

Gentleman: Now it’s called the toStringTag

Stemm: Which means you can only really determine an object’s type through a duck test.