title: Why does RegExp.rightContext raise an invalid access error inside an anonymous function?
body: <p>This function raises an "invalid access" error in Chrome, returns the wrong result in IE (pirate_bar_pirate_baz), and works as expected in Firefox (pirate_bar_ninja_baz). If you remove the global flag from the regular expression, it works fine, but only for the first "foo" instead of both. What's the problem?</p>
  
  <pre><code>regex = /foo/g;
  //regex = /foo/;
  
  "foo_bar_foo_baz".replace(regex, function(str) {
    if (RegExp.rightContext == "_baz") {
      return "ninja";
    } else {
      return "pirate"; 
    }
  });
  </code></pre>