IE6/7/8/9不支持exec的简写方式

如下

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 

posted on 2011-05-25 16:57  snandy  阅读(1564)  评论(2编辑  收藏  举报