For example, I would like to do something like this:
var t = /^foo(bar)?$/i;
alert(typeof t); //I want this to return "regexp"
obj.constructor.name === "RegExp"
obj instanceof RegExp
You can use instanceof operator:
var t = /^foo(bar)?$/i; alert(t instanceof RegExp);//returns true
In fact, that is almost the same as:
var t = /^foo(bar)?$/i; alert(t.constructor == RegExp);//returns true
But you can use this trick above or others like duck type checking, for example, checking if such object has any vital methods or properties, or by its internal class value(by using