On Thu, Oct 9, 2008 at 9:01 PM, Derrell Lipman <
[EMAIL PROTECTED]> wrote:

>
> Hi Stefan.  What you describe is exactly the "problem" that I don't
> understand.  With a regular expression literal, as with an object literal in
> 'var testobj={x:2}' or an array literal in 'var testarr=[23,42], If
> someplace in that method I say 'testobj.x=3;' the next time into that
> method, it'll reinitialize testobj to an object in which x has the value 2.
> Similarly, I would expect a new instantiation of a regular expression on
> each call into the method. It's not assigned to a static or global variable;
> it's a literal assigned to a local variable.  Do you see any rationale for
> the regular expression retaining its state on subsequent calls to doTest()?
> Shouldn't we get a brand new, just-initialized regular expression object
> assigned to illegalChars on each call to doTest()?
>

Here's a minor change to the application to demonstrate what I'm talking
about.  We can see that on each call, testobj.x and testarr[0] contain the
values initialized by the object and array literals, respectively, but
illegalChars.lastIndex is clearly referencing the original regular
expressing object, not a newly-instantiated one...

/*
#require(qx.log.appender.Native)
#require(qx.log.appender.Console)
*/

qx.Class.define("custom.Application",
{
  extend : qx.application.Standalone,
  members :
  {
    main: function()
    {
      this.base(arguments);

      this.doTest("123123", true);
      this.doTest("12b13b", true);
      this.doTest("12b13b", true);
      this.doTest("12b13b", true);
      this.doTest("12b13b", true);

      this.doTest("123123", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
      this.doTest("12b13b", false);
    },

    doTest : function(s, reset)
    {
      var illegalChars = /[^0-9]/g;
      var testobj = { x : 2 };
      var testarr = [ 23, 42 ];
      var resetText = "without";
      this.debug("lastIndex=" + illegalChars.lastIndex + ", " +
                 "testobj.x=" + testobj.x + ", " +
                 "testarr[0]=" + testarr[0]);

      if (reset)
      {
        illegalChars.lastIndex = 0;
        resetText = "with";
      }

      var isIllegal = illegalChars.test(s);
      this.debug(s + " " + resetText +
                 " reset: " + (isIllegal ? "illegal" : "legal"));

      testobj.x = 3;
      testarr[0] = 223;
    }
  }
});
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to