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 trialPhuc Le
5,182 PointsWhat does the EventEmitter.call(this) mean in profile.js?
There are 2 statements in profile.js
which are complex for me
util.inherits( Profile, EventEmitter );
: In my opinion, it is used to inherit the prototype methods from EventEmitter into Profile, so we can call on
method like this:
let profile = new Profile();
profile.on('data', callback{...});
Is that correct?
But I don't know what does EventEmitter.call(this)
mean? Because I tried to delete this statement and the project still works well.
3 Answers
Phuc Le
5,182 PointsCould somebody give me a answer?
David Mendiola
Full Stack JavaScript Techdegree Student 16,579 Points.call is a prototype available to all JS functions. It specifies what to use for "this" followed by any arguments for the function. This example taken from mdn.
function greet() {
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
}
var i = {
person: 'Douglas Crockford', role: 'Javascript Developer'
};
greet.call(i); // Douglas Crockford Is An Awesome Javascript Developer
Butler Fuqua
5,706 PointsI have the same question. I don't really see what it means, or why it is necessary. Also, what does the code above it mean? it looks to be in comments, but my syntax highlighter has highlighted it.
/**
* An EventEmitter to get a Treehouse students profile.
* @param username
* @constructor
*/