如下

var ary = /h/('hello');
alert(ary);

IE6/7/8/9中报错

Firefox/Safari/Chrome/Opera的最新版本均弹出了“h”


以上写法等价于

var ary = /h/.exec('hello');

即 Firefox/Safari/Chrome/Opera浏览器中使用exec方法时可以去掉“exec”用 “正则直接量+()” 方式使用。

IE10 Platform Preview 仍然不支持该简写方式。


相关:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/exec 

相关文章:

  • 2021-11-06
  • 2021-08-21
  • 2022-01-12
  • 2021-08-22
  • 2022-03-08
  • 2021-10-23
  • 2022-01-11
  • 2022-12-23
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-03-02
  • 2022-12-23
相关资源
相似解决方案