2
  dispose: function() {
    var disposer;
    while (disposer = this._disposers.shift()) { // expected a conditional expression and instead saw an assignment.
      disposer();
    }
  },

jshint不高兴在循环disposer中分配。while

有什么方法可以保持这种逻辑并使其jshint友好吗?

4

3 回答 3

6

您可以简单地使用().

dispose: function () {
    var disposer;
    while ((disposer = this._disposers.shift())) {
        disposer();
    }
}
于 2012-08-22T19:54:19.980 回答
3

除非我错过了什么...

dispose: function() {
    var disposer = this._disposers.shift();
    while (disposer) {
        disposer();
        disposer = this._disposers.shift();
    }
},

你可能还想加强你的条件:

while (typeof disposer === 'function') {

工作示例:http: //jsfiddle.net/DPNYq/

于 2012-08-22T19:48:29.290 回答
1
dispose: function() {
  var disposer;
  while (typeof (disposer = this._disposers.shift()) === 'function') {
    disposer();
  }
},
于 2012-08-22T19:53:54.547 回答