<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>chap07</title>
<script>
function make_a_matcher(){
return /a/gi;
}
var x = make_a_matcher();
var y = make_a_matcher();
x.lastIndex = 10;
document.writeln('<div>x.global : '+x.global+'<div>');
document.writeln('<div>x.ignoreCase : '+x.ignoreCase+'<div>');
document.writeln('<div>x.lastIndex : '+x.lastIndex+'<div>');
document.writeln('<div>x.multiline : '+x.multiline+'<div>');
document.writeln('<div>x.source : '+x.source+'<div>');
document.writeln('<div>y.global : '+y.global+'<div>');
document.writeln('<div>y.ignoreCase : '+y.ignoreCase+'<div>');
document.writeln('<div>y.lastIndex : '+y.lastIndex+'<div>');
document.writeln('<div>y.multiline : '+y.multiline+'<div>');
document.writeln('<div>y.source : '+y.source+'<div>');
</script>
</head>
<body>
</body>
</html>
I'm studying JavaScript with "JavaScript The Good Parts" written by Douglas Crockford. He described that RegExp objects made by regular expression literals share a single instance and above example.
The result in the book is y.lastIndex : 10
. But my result is y.lastIndex : 0
.
I would appreciated if you tell me the exact reason of this diffrent result.