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 Link to comment https://forums.phpfreaks.com/topic/78079-textreplace/ 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. Link to comment https://forums.phpfreaks.com/topic/78079-textreplace/#findComment-395274 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. Link to comment https://forums.phpfreaks.com/topic/78079-textreplace/#findComment-395788 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. Link to comment https://forums.phpfreaks.com/topic/78079-textreplace/#findComment-395896 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)) { } Link to comment https://forums.phpfreaks.com/topic/78079-textreplace/#findComment-398263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.