JS constructor function methods

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! = )

function PhoneNumberFormatter(numbers) {
  this.numbers = numbers;

PhoneNumberFormatter.prototype.render = function() {
  var string = '';
  string += this.parenthesize(this.getAreaCode());
  string += ' ';
  string += this.getExchangeCode();
  string += '-';
  string += this.getLineNumber();
  return string;

PhoneNumberFormatter.prototype.getAreaCode = function() {
    return this.slice(0, 3);

PhoneNumberFormatter.prototype.getExchangeCode = function() {
    return this.slice(3, 6);

PhoneNumberFormatter.prototype.getLineNumber = function() {
    return this.slice(6)

PhoneNumberFormatter.prototype.parenthesize = function(string) {
  return '(' + string + ')';

PhoneNumberFormatter.prototype.slice = function(start, end) {
  return this.numbers.slice(start, end).join('');

var phoneNumberOne = new PhoneNumberFormatter([6, 5, 0, 8, 3, 5, 9, 1, 7, 2]);


I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

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 keep getting an error that .slice is not a function if I don’t have the prototype.slice() function in the code.

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.

okay, thanks for your help.