简体   繁体   English

goog.Timer.callOnce不符合形式参数:谷歌关闭

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

I get the error for formal parameter not matching when using goog.Timer.callOnce even when I think I have declared everything correctly. 使用goog.Timer.callOnce时出现形式参数不匹配的错误,即使我认为我正确声明了所有内容也是如此。

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

the method definition looks like 方法定义看起来像

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

The error looks like 错误看起来像

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);

I also tried typecasting /** @type {function()} */ but even this didnt work 我也尝试过类型转换/** @type {function()} */但是即使这样也没有用

The compiler is expecting a function that takes no arguments (because goog.Timer isn't going to pass any arguments) but you're passing a function that expects one argument. 编译器期望一个不带参数的函数(因为goog.Timer不会传递任何参数),但您传递的是一个带参数的函数。 Either change the function so that it doesn't take an argument, or make the argument optional: 更改函数以使其不接受参数,或者使参数可选:

/**
 * @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