欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Javascript lastIndex 正則表達(dá)式的一個(gè)疑惑

 更新時(shí)間:2009年01月13日 00:54:46   作者:  
Javascript lastIndex 正則表達(dá)式
看下面這段代碼:
function test(s){
var reg = /./g;
console.log(reg.exec(s));
console.log(reg.lastIndex);
var reg = /./g;
console.log(reg.exec(s));
console.log(reg.lastIndex);
}
test("abcd");
test("efgh");
我以為輸出的lastIndex的值應(yīng)該都是1,但是實(shí)際上的輸出如下:
a
1
a
1
f
2
f
2
感覺(jué)就像是在第二次調(diào)用test的時(shí)候第2行和第6行并沒(méi)有產(chǎn)生新的正則表達(dá)式,其之前的屬性lastIndex還保留著(lastIndex=1)。這有點(diǎn)不合常理,頭疼中。。。。。。

相關(guān)文章

最新評(píng)論