Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what causes /*global module: false*/ in grunt.js

Many grunt.js-script starts with:

/*global module:false*/
module.exports = function(grunt) {

But what the cause of the comment in the first line?

like image 413
TLindig Avatar asked Dec 20 '12 13:12

TLindig


People also ask

What is global module in node JS?

Global modules are node packages that are installed on your system rather than your project directory. They allow us to use the package as a tool anywhere on the local computer. By saying global, we are talking about the scope of usage of these modules.

How do you assign a value to a global variable in node JS?

To set up a global variable, we need to create it on the global object. The global object is what gives us the scope of the entire project, rather than just the file (module) the variable was created in. In the code block below, we create a global variable called globalString and we give it a value.

What is global this in JavaScript?

The globalThis property provides a standard way of accessing the global this value (and hence the global object itself) across environments. Unlike similar properties such as window and self , it's guaranteed to work in window and non-window contexts.

What is global scope in node JS?

While in browsers the global scope is the window object, in nodeJS the global scope of a module is the module itself, so when you define a variable in the global scope of your nodeJS module, it will be local to this module. You can read more about it in the NodeJS documentation where it says: global.


1 Answers

It's a directive for JSLint or JSHint. It tells the JSLint/JSHint parser that the identifier module is defined elsewhere, so it doesn't throw an error telling you that module is undefined. Without it, the parser will encounter the reference to module and think that you're trying to refer to an undefined variable.

From the JSLint docs:

JSLint also recognizes a /*global*/ directive that can indicate to JSLint that variables used in this file were defined in other files. The directive can contain a comma separated list of names.

And the JSHint docs:

In addition to options, you can let JSHint know what global variables it should expect:

    /*global DISQUS:true, jQuery:false */

In the example above, JSHint will allow you to override DISQUS, but complain if you try to override jQuery.

like image 192
James Allardice Avatar answered Sep 17 '22 07:09

James Allardice