Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Defineing dot function on a String to call several function

I wonder how I can define some dot function in js like .toupperCase that can call on a string or object without getting any parameters. For example I want to define a function on a string that calls a several function itself like

let ex = "hi .this is  &$234234 a test @#";
let tmp = ex.textformating();

String.prototype.textformating = function (){
    return this.replace(/[^a-z0-9 ]/gi, '  ').trim();
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your code works fine. You just have to define the function before you call it.

String.prototype.textformating = function (){
    return this.replace(/[^a-z0-9 ]/gi, '  ').trim();
}

let ex = "hi .this is  &$234234 a test @#";
let tmp = ex.textformating();

console.log('original:', ex)
console.log('formatted:', tmp)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading