Why assign `this` to `self` and run `self.method()`?

后端 未结 5 2088
我在风中等你
我在风中等你 2021-02-19 07:30

I\'m reading the source from mongoose

Collection.prototype.onOpen = function () {
  var self = this;
  this.buffer = false;
  self.doQueue();
};
<
5条回答
  •  野性不改
    2021-02-19 07:52

    self is a copy of 'this',but it always refer to the right object,and 'this' may not.

提交回复
热议问题