簡體   English   中英

goog.Timer.callOnce不符合形式參數:谷歌關閉

[英]goog.Timer.callOnce does not meet formal parameter : Google Closure

使用goog.Timer.callOnce時出現形式參數不匹配的錯誤,即使我認為我正確聲明了所有內容也是如此。

goog.Timer.callOnce(/** @type {function} */ this.doSomething,0,this); 

方法定義看起來像

/**
* @param {!goog.events.Event} e
*/
model.someModel.prototype.doSomething = function(e){
}

錯誤看起來像

ERROR - actual parameter 1 of goog.Timer.callOnce does not match formal parameter
==> default: [ERROR] found   : function (this:model.someModel, goog.events.Event): undefined
==> default: [ERROR] required: (function (this:model.someModel): ?|null|{handleEvent: function (): ?})
==> default: [ERROR] goog.Timer.callOnce(/** @type {function} */doSomething,0,this);

我也嘗試過類型轉換/** @type {function()} */但是即使這樣也沒有用

編譯器期望一個不帶參數的函數(因為goog.Timer不會傳遞任何參數),但您傳遞的是一個帶參數的函數。 更改函數以使其不接受參數,或者使參數可選:

/**
 * @param {!goog.events.Event=} opt_e
 */
model.someModel.prototype.doSomething = function(opt_e) {
  if (opt_e) {
    ...
  } else {
    ...
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM