javascript - Array prototype works in chrome extension but gives TypeError in firefox -


i found helpful code snippet here on stackoverflow:

array.prototype.clean = function(deletevalue) {     (var = 0; < this.length; i++) {         if (this[i] == deletevalue) {                      this.splice(i, 1);             i--;         }     }     return this; }; 

i use remove empty values arrays in chrome extension im porting firefox. use ist this:

foobar = foo.concat(bar).clean('').tostring(); 

which works fine in chrome, in firefox typeerror:

typeerror: foo.concat(...).clean not function 

any suggestions might problem?

//edit//

foo , bar arrays, foo comes json gets parsed this:

var json = {property: 'a,b,c,d,e,f,g'}; json = json.property.split(','); 

and bar textarea gets parsed this:

function digesttextfield (string) {     // takes string of format "a, b , c", trims spaces, converts lower case     var rawtext = document.getelementbyid(string + 'events').value,         digestedtext = rawtext.split(','),         i;      (i = 0; < digestedtext.length; += 1) {         digestedtext[i] = digestedtext[i].tolowercase()                             .replace(/^\s\s*/, '').replace(/\s\s*$/, '');     }     return digestedtext; } 

both saved to, , read simplestorage, before .clean('') called.

there no problem in code posted, maybe add clean prototype after calling it? following works in xul application:

function jsdump(str) {   components.classes['@mozilla.org/consoleservice;1']             .getservice(components.interfaces.nsiconsoleservice)             .logstringmessage(str); } array.prototype.clean = function(deletevalue) {     (var = 0; < this.length; i++) {         if (this[i] == deletevalue) {                      this.splice(i, 1);             i--;         }     }     return this; }; var foo = {property: 'a,b'}; foo = foo.property.split(','); var bar="5,6,,7,".split(",");  jsdump("array has clean:"+array.prototype.hasownproperty("clean")); jsdump("is foo array:"+(foo instanceof array)); jsdump("is bar array:"+(bar instanceof array)); jsdump(foo.concat(bar).clean('').tostring()); 

in defaults\preferences\prefs.js:

pref("browser.dom.window.dump.enabled", true); pref("javascript.options.showinconsole", true); pref("javascript.options.strict", true); pref("nglayout.debug.disable_xul_cache", true); pref("nglayout.debug.disable_xul_fastload", true); 

starting application with:

firefox --app application.ini -jsconsole 

Comments