方法RegExp.prototype.exec在不兼容的接收器上调用

时间:2017-03-30 08:35:18

标签: javascript

最近,我遇到了RegExp.prototype的问题。正常情况下,RegExp.prototype是一个空的正则表达式,但是,我尝试在控制台中使用RegExp.prototype.test(''),这将是错误的。为什么会显示错误

image with error

1 个答案:

答案 0 :(得分:0)



console.log(RegExp.prototype.test.toString());
//RegExp.prototype.test is a native function
//if you want call this function,you should new a Regexp
console.log(new RegExp(/^$/).test(''));




相关问题