我在使用 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 {
...
}
}
关于javascript - google.Timer.callOnce 不满足形参 : Google Closure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061969/