scottybwoy Posted November 20, 2007 Share Posted November 20, 2007 Why would text.replace give an error that it is not a function and halt the script? Here is how it is evoked: if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@'). replace(/"[^"\\\n\r]*""|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g, ']'). replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { } Thanks Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 20, 2007 Share Posted November 20, 2007 I'm fairly new to javascript as I'm more a php guy, but shouldn't you need a ' around the ereg? if (/^[\],:{}\s]*$/.test(text.replace('/\\./g', '@'). replace('/\\./g', '@') Just a thought. Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted November 21, 2007 Author Share Posted November 21, 2007 Thanks, it was not a problem with the code. I just used that one as an example. What I wanted to know is why that error comes up sometimes. I have seen it with a few functions, but also new to Java, (more a php person) just wanted to know why. Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 21, 2007 Share Posted November 21, 2007 sorry I can't help you their. I've only just started working with javascript last night.. so you probably know more than me the syntax throws me off a bit. I keep doing silly things like: toUpperCase(somevar); instead of: somevar.toUpperCase(); Which does throw up a non-function error. Maybe that's what's happening.. You're just setting it wrong sometimes. Quote Link to comment Share on other sites More sharing options...
cha0sriderx Posted November 24, 2007 Share Posted November 24, 2007 Why would text.replace give an error that it is not a function and halt the script? Here is how it is evoked: if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').replace(/"[^"\\\n\r]*""|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { } Thanks first im not sure if u can do replace like that, i dunno for a fact since i havent been coding js for long. also try using var's instead of the long strings in the if. this could be wrong, im just using what ive learned so far:P. exp = '/^[\],:{}\s]*$/'; x = text.replace(/\\./g, '@'); x = x.replace(/"[^"\\\n\r]*""|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g, ']'); x = x.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); if (exp.test(x)) { } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.