Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the conventional way to annotate globals in Javascript?

There's some convention for writing about globals in JS that looks something like /* globals: foo, _ */ placed at the beginning of the file, but I can't remember it for the life of me. It's a miserable thing to search for, too.

The one other thing I can remember about it is that it was useful for silencing related linter errors.

like image 491
bright-star Avatar asked Nov 20 '25 11:11

bright-star


1 Answers

The correct way to tell JSLint about globals is to use the globals directive. For example:

/*globals globalFunction, anotherGlobal, oneMore */
like image 161
Ryan Dantzler Avatar answered Nov 23 '25 01:11

Ryan Dantzler