Jump to content

Recommended Posts

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

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

sorry I can't help you their. I've only just started working with javascript last night.. so you probably know more than me :D

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.