p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional JavaScript for Web Developers 3rd edition (http://p2p.wrox.com/forumdisplay.php?f=669)
-   -   chapter 5, regexp question (http://p2p.wrox.com/showthread.php?t=88064)

kipenzam July 22nd, 2012 03:00 AM

chapter 5, regexp question
 
hi everyone

in 130 page, there are discussion of difference of creating RegExp with literal and constructor. the book says RegExp created by literal shares same instance, so..

Code:

var re = null,
    i;
for (i=0; i < 10; i++){
    re = /cat/g;
    re.test("catastrophe");
}

would return
Code:

true
false ('cause it starts at index 3)
true ('cause it starts over)
false
...

I thought I got it clearly, but when I tested it in IE 8, every call of test() returned true. am I missing something important? please help


All times are GMT -4. The time now is 09:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.