I\'m reading the source from mongoose
Collection.prototype.onOpen = function () {
var self = this;
this.buffer = false;
self.doQueue();
};
<
Most likely the developer wanted consistency, but failed at doing so.
Otherwise you'd be using this
in some functions, self
in other functions and a mix of both in other functions, depending on where you use the object and if you use nested functions/callbacks.
By always assigning this to self and then using the latter you have one additional assignment at the very beginning of each function but you always use self
to access the object.
However, what the developer did in the code you posted does not make much sense. He should either use self
or this
both times instead of a mix that is not even necessary.