Upon testing the code from a book on page 72 in both FF and NodeJS, it was discovered that y.lastIndex
equaled 0
and x === y
evaluated to false
.
Why is there a discrepancy between the book's information and the actual behavior of the code?
function make_a_matcher() {
return /a/gi;
}
var x = make_a_matcher();
var y = make_a_matcher();
// Be aware that x and y reference the same object!
x.lastIndex = 10;
document.writeln(y.lastIndex); // 10