首页 > 语言 > JavaScript > 正文

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

2024-05-06 14:24:35
字体:
来源:转载
供稿:网友
如下
代码如下:
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 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选