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

前端 未结 1 645
野的像风
野的像风 2020-11-27 13:51

John Resig wrote a nifty Class function, swanky. I\'m trying to figure out what is going on, and have pretty much everything figured out except a single line:



        
相关标签:
1条回答
  • 2020-11-27 14:22

    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.

    0 讨论(0)
提交回复
热议问题