Hello, i didn't understand the this keyword in the below code. I know that
"The value of this, when used in a function, is the object that "owns" the
function.". However, in this code, i can't see any object. What does this
refer to in below codes?
Is Radio a function or constructor? How can we understand it?
var Radio = function(station) {
// what does this refer to?
setTimeout(function() {
// what does this refer to?
});
this.on('newListener', function(listener) {
console.log('Event Listener: ' + listener);
});
};
from the comments :
// we need to store the reference of `this` to `self`, so that we can use the
current context in the setTimeout (or any callback) functions
// using `this` in the setTimeout functions will refer to those funtions,
not the Radio class
but didn't understand
Quoted from : http://www.hacksparrow.com/node-js-eventemitter-tutorial.html
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/f78965bc-0abc-4c4b-8191-48a61957253a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.