Strange JavaScript idiom – what does “/xyz/.test(function(){xyz;})” do?

It is just a quick & dirty way to check if “function decompilation” works.

The RegExp.prototype.test method will take the argument and it will convert it to String, the xyz reference inside the function is never evaluated.

Why would you have to check this?

Because the Function.prototype.toString method returns an implementation-dependent representation of a function, and in some implementation, such older Safari versions, Mobile Opera, and some Blackberry browsers, they don’t actually return anything useful.

Leave a Comment