--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
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 nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/3YvqPyTIt-0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
would you still do that if you want to change something about this? mix self and this?
In addition all previous comments:I don't like name 'self' as alias to 'this' ( I tend to interpret same way as 'this', e.i context of current function). Instead, use same name you would use for your object instance. Example:Client.prototype.doStuff = function() {var client = this;// ... some async code heresetTimeout(function() {client.doneTimeout(); // I think it's more explicit than self.doneTimeout()}, 100);};
On Tuesday, 22 April 2014 06:11:14 UTC+10, Reza Razavipour wrote:I see a lot of code that doesvar self = thisand then they use self instead of this for the duration of the function?Why and when would you use the above pattern?
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
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 nodejs+un...@googlegroups.com.
Douglas Crockford recommends "that" as the alias for this which is an approach that I prefer over self. Self reminds me of Python :-)
2014-04-22 7:44 GMT+03:00 Andrey <andrey....@gmail.com>:
In addition all previous comments:I don't like name 'self' as alias to 'this' ( I tend to interpret same way as 'this', e.i context of current function). Instead, use same name you would use for your object instance. Example:Client.prototype.doStuff = function() {var client = this;// ... some async code heresetTimeout(function() {client.doneTimeout(); // I think it's more explicit than self.doneTimeout()}, 100);};Consider the situation where that `client.something()` ends up somewhere deeply nested and the function isn't that trivial. Someone reading that piece code or jumping to it from search results will have no idea what it points to, because it's not obvious; is it an argument, or what? Where did it come from?