WARNING - dangerous use of the global this object

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?

8
задан Bryan Field 2 August 2012 в 20:17
поделиться