Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Methods with Prototypes

Dongyun Cho
Dongyun Cho
2,256 Points

why external function is hard to match with what method call?

we have function floating around, not connected tot he dice constructor function . Imagine in a larger application where we have dozens of objects and dozens of methods. It may get difficult tracking down which external function works with what method call.

Here's what the teacher said, and I don't understand this.

function diceRoll(){
    var randomNumber = Math.floor(Math.random() * this.sides) + 1;
    return randomNumber;
  }

function Nono(){
  var a = "nono";
  return a;
}

function Yes(){
  var a = "yesyes";
  return a;
}
/**************/

function Dice(sides) {
  this.sides = sides;
  this.roll = diceRoll;
}

var dice6 = new Dice(6);
var dice10 = new Dice(10);

function Whatsoever(name){
  this.name = name;
  this.method = Nono;
}

var variable = new Whatsoever('Cho');

It seems there's not really difficult to track down which external function works with what method call.

1 Answer

Steven Parker
Steven Parker
229,982 Points

It's not so hard in this small example.

I think the idea expressed in the video is that it could be hard when the program is a good bit larger than this one (such as one with "dozens of methods").