I would like to extend the JavaScript String
class to an EoString
class, in order to use custom methods, that have sense only for strings of class EoString
and not for all strings, otherwise I could extend the String
prototype. So I defined the EoString
class like that:
class EoString extends String
{
normalize() { ... }
}
Now I would like to call the normalize()
method on a normal string, after typecasting it to EoString
, like that:
var text = (EoString)'abcd'; // I don't know how to typecast
text.normalize();
So, how can I typecast a normal string to the EoString
class? How can I access the string within the normalize()
method? What should the normalize()
method return? Shall I add a constructor() too?
Thanks