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 Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Populating User Information

EventEmitter

Can anyone explain in a bit of depth the EventEmitter that is used in the profile.js file? Especially the lines:

EventEmitter.call(this);
profileEmitter = this;

2 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

In the object oriented course we talk about inheritance and what the call method does: For the full course: http://teamtreehouse.com/library/objectoriented-javascript

It's used for inheritance purposes. This is the video where we do it in our code for the first time. https://teamtreehouse.com/library/objectoriented-javascript/prototypal-inheritance/updating-the-song-object

The profileEmitter = this; is to make it possible to reference the object instance of the profile emmitter (this) in different contexts. Here's where I discuss it in that course: https://teamtreehouse.com/library/objectoriented-javascript/introduction-to-methods/understanding-this

If you're interested in understanding how that all works take that course and then give the code in the profile.js a read over again :)

Regards
Andrew

Thanks!

I have checked it out the profile.js. But there is no tutorial of profile.js with using Emitter and Utils.

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Yep. Not yet!

profile.js is like including someone else code in a module. All you need to know is the API or what you use to make it work. There's no need to worry about the implementation so much. However, it's good that people are wanting to look in a little deeper and see how it works.

Andrew Chalkley, I appreciate you taking the time to personally answer our questions and the thought you put into creating the videos.

In your last response to this discussion, you wrote, "There's no need to worry about the implementation so much." This line of thinking doesn't seem right to me. If we students are to understand how to build simple websites with nodejs, I believe it's important to understand how the profile.js file was created and also what's up with the util and eventemitter modules. Without that video or series of videos explaining how you came up with that code, we don't get the full picture of what's going on. This incomplete understanding can make it difficult to rework the code for different projects.

I hope Treehouse will amend the oversight of not explaining the code in the profile.js file. In the meantime, I will continue to look outside of Treehouse to understand what's going on.

Thanks again for your instruction and feedback. Cheers :)

Rose