I’ve the following code:
$.each(css, function(i, v) {
css[i] = this.replace('{bind}', bindName, css[i]);
});
I want to replace all {bind}’s with the value of bindName.
To try this I gave bindName the value ‘Test’.
‘css’ is a simple object with data.
var css = {
tabs : 'tab-{bind}',
outerWrapper : 'outerWrapper-{bind}',
innerWrapper : 'innerWrapper-{bind}-{id}-{tab}',
subMenue : 'subMenue-{bind}-{id}',
subMenueItem : 'subMenue-Item'
};
In Firefox I get the error “invalid regular expression flag k” on line 68.
Line 68:
$.each(css, function(i, v) {
css[i] = this.replace('{bind}', bindName, css[i]); // LINE 68
});
If it’s necessary this is my replace funcion:
this.replace = function (s, r, su) {
return su.split(s).join(r);
}
There’s no error in Google-Chrome but in Firefox (newest Version) – can you find the error ?
Change this:
to any of these:
The reason for the error-message is that in Firefox,
String.replacetakes an optional third argument representing regex flags (e.g.'i'or'g'); you’re passing incss[i]for that argument, and Firefox interprets it as containing invalid flags. The reason that Chrome doesn’t give an error-message is that it doesn’t support that nonstandard feature, so it’s simply ignoring that argument entirely.