I know the "self" magic. But look at this snippet from nodejs(not complete).
Socket.prototype.connect = function(options, cb) {
......
var self = this;
var pipe = !!options.path;
if (this.destroyed || !this._handle) {
this._handle = pipe ? createPipe() : createTCP();
initSocketHandle(this);
}
if (typeof cb === 'function') {
self.once('connect', cb);
}
timers.active(this);
self._connecting = true;
self.writable = true;
......
}
It is my understanding that we must use self to create a closure. Here there is no closures in these lines but the author use both after assigning this to self. Does it make any difference here?
this
in one place might just be an oversight.self
is set tothis
they're the same variable. I'm not sure why the author mixes the two.