Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3303200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:55:56+00:00 2026-05-17T20:55:56+00:00

In Google Closure Compiler I get the warning WARNING – dangerous use of the

  • 0

In Google Closure Compiler I get the warning

WARNING – dangerous use of the global this object

Here is an example. The error line and offset refers to the beginning of the word this

function aToggle() {
  if(shown)
    toggle.show()
  else
    toggle.hide()
  $(this).text(shown ? 'Click to hide' : 'Click to show')
  shown = !shown
}
link.onclick = aToggle

I would just change it to an anonymous method, but I am re-using aToggle elsewhere in the file, so it needs to be named.

I could mark aToggle as /**@constructor*/ — but it is not a constructor. Is there another annotation I can use to eliminate this warning, or am I stuck between marking it as constructor or having a bunch of useless warnings show up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:55:57+00:00Added an answer on May 17, 2026 at 8:55 pm

    Edit: I’ve been reading Closure: The Definitive Guide, and I just realized that you can simply add the /** @this {Element} */ annotation before your event handler to make Closure Compiler stop complaining.

    See the Closure Compiler warning reference. The Closure Compiler gives this warning when you use this within a function that is not either annotated /** @constructor */ or is within the prototype of a class. The compiler assumes that you’ll never use this when a function is called in the context of another object (which is what event callbacks do).

    Some places that you might have to change to make Closure Compiler stop complaining with this warning:

    • Don’t use link.onclick = ... directly, because you have to mess with this and e || window.event. Instead, use jQuery to wrap the event handler, since jQuery’s event object has e.currentTarget.
    • If you’re using this within a jQuery.each, replace this with the second parameter of your function. E.g., jQuery.each([1, 2, 3], function(i, val) { ... val ... };.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EBay's VJET and Google's Closure Compiler both use type annotations in Javascript comments. Why
Any ideas on how to use Google Closure Compiler to combine multiple JavaScript files
I'm trying to use the Google Closure Compiler to split my application code based
I wanna use Google Closure Compiler to compile my js codes.I write a makefile
I'm using Google Closure Compiler application (command line interface). When I run it I
I want to use the google closure compiler on the javascript source we're using.
I'm getting a weird error using google closure compiler. I'm using externs to indicate
I'm trying to get KineticJS to work with Google Closure Compiler. KineticJS, however, generated
I am trying to get Google Closure Compiler to work to compile my javascript
When use the Google Closure Compiler advanced optimizations on the following code: function add(v1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.