Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suppose you mean type warnings when you are using VERBOSE or checkTypes.</p> <p>Put the following into any file:</p> <pre><code>/** * @fileoverview * @suppress {checkTypes} */ </code></pre> <p>to turn off type checking <em>for that file only</em>. You can <code>@suppress</code> many other things as well. Read the Closure Compiler docs for more details.</p> <h2>Dangerous use of "this"</h2> <p>However, if you are talking about "dangerous use of this" warnings, <strong>DO NOT</strong> ignore them. They refer to places where:</p> <ol> <li>You have a namespace</li> <li>You defined a function within that namespace</li> <li>You use "this" inside that function -- and this can refer to the namespace</li> <li>That namespace may be <em>flattened</em> by the compiler</li> </ol> <p>For example:</p> <pre><code>foo.bar.hello = "Hello World!"; foo.bar.baz = function() { alert(this.hello); }; foo.bar.baz(); // this --&gt; foo.bar </code></pre> <p>The "alert" statment will be flagged by a compiler warning of "dangerous use of this". Why? Remember, if the compiler <em>flattens</em> the "foo.bar" namespace:</p> <pre><code>$foo$bar$hello$ = "Hello World!"; $foo$bar$baz$ = function() { alert(this.$hello$); } $foo$bar$baz$(); // this --&gt; window </code></pre> <p>Notice I am using debug variables renaming here. In reality, "$foo$bar$baz" may be renamed just to "a".</p> <p>You can see immediately that the call to <code>foo.bar.baz()</code> will fail because "this" no longer refers to "foo.bar", but refers to the global object. You code will crash with a loud <strong>CRANK!</strong></p> <h2>Exception cases when "this" is OK</h2> <p>Now, there are cases where usage of "this" is OK. For example, in event handlers. "this" will automatically point to the DOM node that raised that event.</p> <p>In these cases, you need to use the following type of JsDoc directive:</p> <pre><code>/** @this {Node} */ </code></pre> <p>to specify the type expected for "this" in order to shut the compiler up.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload