troubleshooting Question

My simple JS functions failing after adding DataTables()

Avatar of Ralph
RalphFlag for United States of America asked on
JavaScript
5 Comments2 Solutions301 ViewsLast Modified:
I am NOT a JS expert, I just program well in other languages and do the same w/ what I know about JavaScript.

Some of this code is not even being accessed, but apparently scanned.
All have been in my 'library' file for months, some of it accessed at times, some never.  Even the `never` is burping.

The never-used code that burps:
// *************************************************************************************************

String.prototype.string_reverse = function () 
{ alert('this='+this);                                         // Object = Window!?
  return this.split('').reverse().join('');           // CRASHes
};

// usage:  str = str.string_reverse() ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function reverse(s) 
{
  return s.split('').reverse().join('');
}
// *************************************************************************************************
// *************************************************************************************************

String.prototype.replaceLast = function (what, replacement) 
{
  return what.string_reverse().replace(new RegExp(what.string_reverse()), replacement.string_reverse()).string_reverse();
};

// usage:  str = str.replaceLast('one', 'finish');
The is-used code that burps:
// *************************************************************************************************

String.prototype.strip_phone_format = function ()
{
  
  var phone=this.replace("(","") ;     // Error msg:  LibraryScripts.js:318 Uncaught TypeError: this.replace is not a function
  phone=phone.replace(" ","") ;
  phone=phone.replace(")","") ;
  phone=phone.replace("-","") ;
  
  return phone ;
} ;// *************************************************************************************************
// *************************************************************************************************

String.prototype.add_phone_format = function ()
{
  var just_numbers = this.strip_phone_format() ;
  
  return "("+just_numbers.substr(0,3)+") "+just_numbers.substr(3,3)+"-"+just_numbers.substr(6) ;
} ;

Two, three questions.
  • Why is this just complaining now?
  • Can I get help w/ the as-of-now unused code
  • And the I-Need code?

Thanks!
Ralph

(DataTables() AJAX questions likely to follow.)
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros