I have a string method String.prototype.splitName() that splits an author's name (a string) in first name(s) and a last name. The statement var name = authorName.splitname(); returns an object literal name with name.first = "..." and name.last = "..." (properties of name have string values).
Recently I was told that it is unwise to have splitName() as a method of the public String() class, but that I should make a private subclass of String and extend the subclass (instead of the public class) with my function. My question is: how do I perform subclassing for strings so that after I assign authorName to the new subclass name = authorName.splitname(); is still a valid statement? And how would I assign authorName to the new private subclass of String?
lengthis not even guaranteed to be equal to its length.