gpt4 book ai didi

javascript - 什么原因/*全局模块: false*/in grunt. js

转载 作者:IT老高 更新时间:2023-10-28 23:24:02 25 4
gpt4 key购买 nike

许多 grunt.js 脚本以:

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

但是第一行注释的原因是什么?

最佳答案

它是 JSLint 或 JSHint 的指令。它告诉 JSLint/JSHint 解析器标识符 module 是在别处定义的,因此它不会抛出错误,告诉您 module 未定义。没有它,解析器将遇到对 module 的引用,并认为您正在尝试引用 undefined variable 。

来自 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.

还有 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.

关于javascript - 什么原因/*全局模块: false*/in grunt. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13973186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com