View Single Post
  #1 (permalink)  
Old July 22nd, 2012, 03:00 AM
kipenzam kipenzam is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote