This seems odd and I can't find any documentation stating why it's so...
This application has a function which tests a string for containing only
digits. It uses a regular expression literal assigned to a local variable
in a function. That regular expression, however, appears to be persistent
across calls to the function. The first set of three calls to the doTest()
function yield correct results because the regular expression's lastIndex
property is explicitly reset 0. The subsequent three calls which do not
explicitly reset it, yield an incorrect result on the last value which is
identical to the second-to-last value. Can anyone explain? This is in
FireFox 3.0.3.
/*
#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("123", true);
this.doTest("12b", true);
this.doTest("12b", true);
this.doTest("123", false);
this.doTest("12b", false);
this.doTest("12b", false);
},
doTest : function(s, reset)
{
var illegalChars = /[^0-9]/g;
var resetText = "without";
if (reset)
{
illegalChars.lastIndex = 0;
resetText = "with";
}
var illegal = illegalChars.test(s);
this.debug(s + " " + resetText + " reset: " + (illegal ? "illegal" :
"legal"));
}
}
});
Results:
3250ms custom.Application[d]: 123 with reset: legal
3257ms custom.Application[d]: 12b with reset: illegal
3263ms custom.Application[d]: 12b with reset: illegal
3269ms custom.Application[d]: 123 without reset: legal
3276ms custom.Application[d]: 12b without reset: illegal
3282ms custom.Application[d]: 12b without reset: legal <== WRONG
-------------------------------------------------------------------------
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