簡體   English   中英

如何使用Closure Compiler定義函數中“ this”的類型

[英]How to define type of “this” in function with Closure Compiler

我的項目使用Closure Compiler的目標是實現100%的鍵入,但我正在努力嘗試一個類似於以下所示的簡單jQuery模式:

$Controls.on('change input', /** function(this:Element) */ function () {
    $(this).removeClass('is-invalid').next('.invalid-feedback').remove();
});

有或沒有注釋/** function(this:Element) */ ,出現以下錯誤:

js/quote.js:61: WARNING - could not determine the type of this expression
        $(this).removeClass('is-invalid').next('.invalid-feedback').remove();
          ^^^^

我以為我從Github Wiki的“ this類型的功能”部分中找到了標題為“封閉類型系統中的類型”的答案,但這似乎並沒有達到我的預期。

如何指定的類型, this對於關閉編譯器?

感謝@RandyCasburn的評論

/** function(this:Element) */應該更改為** @this {Element} */以將函數上下文的類型** @this {Element} */轉換為Element

我認為/** function(this:Element) */應該用於定義帶有元素上下文的函數的參數類型

暫無
暫無

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

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