ITeye博客

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

zhouyrt · 2011-08-20 08:11 · Brower compatibility · Web前端 · Markdown

如下

 

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。