Skip to content

Instantly share code, notes, and snippets.

@ccnokes
Last active August 31, 2016 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccnokes/5b9e372aff90a57b435d78e087a0c90b to your computer and use it in GitHub Desktop.
Save ccnokes/5b9e372aff90a57b435d78e087a0c90b to your computer and use it in GitHub Desktop.
//custom string manipulation class
class MyString {
constructor(str) {
this.str = str;
}
replaceVowels(replacement) {
this.str = this.str.replace(/a|e|i|o|u/gi, replacement);
}
//The valueOf() method returns the primitive value of the specified object.
valueOf() {
return this.str;
}
}
//instantiate it
let myStr = new MyString('test');
//call custom method
myStr.replaceVowels('*');
//now interact with it like it's a normal string
let newStr = 'hi there ' + myStr;
//=> "hi there t*st"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment