0

I'm running jshint on a javascript file, and some of the functions have dots in their names (as a way of namespacing). In particular, I'm using the d3 library, and I have a lot of code that looks like

d3.select("something")

Do I just need to turn off jshint's checking of using undefined variables? Or is there a way to suppress just certain variable names from being checked. I'm using grunt to build the project.

Charles
  • 50,943
  • 13
  • 104
  • 142
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
  • you should try adding in the first line something like `/*global d3: true*/`. I'm using jshint in aptana and if i use this line for the objects that i know they exist it won't throw any warning. – helly0d Nov 28 '12 at 20:33

1 Answers1

4

Wrong.

You are calling the select method on the d3 variable.
You're getting a warning because JSHint doesn't know about the d3 variable.

You need to tell it that the d3 global has been defined elsewhere, like this:

/*global d3:false */

The :false will tell it to complain if you ever overwrite the global.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • in the d3 source code, there is a definition that looks like d3.select = function(selector) {...}. Doesn't that indicate the function name is d3.select? – Jeff Storey Nov 28 '12 at 20:32
  • No. That assigns a value (which happens to be a function) to the `select` property of the `d3` variable. – SLaks Nov 28 '12 at 20:32
  • @JeffStorey No, the decimal is syntactic sugar for d3["select"], you are storing the method into d3. – TheZ Nov 28 '12 at 20:33
  • @JeffStorey d3 is an object, yes. – TheZ Nov 28 '12 at 20:33
  • I have another library though has a similar function definition - my.somefunc = function(...) {}. Is that creating a "my" variable even if it wasn't created elsewhere? – Jeff Storey Nov 28 '12 at 20:34
  • @JeffStorey If 'my' is not defined then an error will be thrown. Are you sure it doesn't exist beforehand? You could add an `alert(my);` line before that assignment to test it really quickly. – TheZ Nov 28 '12 at 20:35