I am wondering why I need the prototype.slice method below. Why can’t I just use slice.(3,6).join(’’) inside my other methods? When the interpreter doesn’t find the method on the PhoneNumberFormatter object, wouldn’t it just look up the prototype chain to find slice and join on the Array prototype? Any help would be much appreciated. Thanks! = )
I don’t think “need” is the right word. These look like convenience methods for a data type. If you plan on calling .join after .slice every time, then you might as well have a method that does the joining for you.
I see what you’re saying. Unless you set an array object as the PhoneNumberFormatter’s prototype, it’s not going to be able to look it up. That’s why you define a slice method.