node.js - 功能错误,但功能有效 - 为什么?
问题描述
我有一个函数可以生成一个随机文件名,格式为 1 到 20 之间的数字。请参见下面的代码"greetingXX.gif"
:"XX"
1 function getGIF(callback) {
2 let randomGIF;
3 let gifName = "greeting";
4 const GIF_EXTENSION = ".gif";
5 const MAX_GREETING = 20;
6 randomGIF = Math.floor(Math.random() * MAX_GREETING) + 1;
7 if (randomGIF < 10) {
8 gifName += "0" + randomGIF;
9 } else {
10 gifName += randomGIF;
11 }
12 gifName += GIF_EXTENSION;
13 callback(gifName);
14 }
该功能有效,但在 WebStorm 中我收到以下警告:
Unused Variable randomGIF (Line 2)
Unused constant MAX_GREETING (Line 5)
Element MAX_GREETING is not imported (Line 6)
Variable gifName might not have been initialised (Line 8 and Line 10)
就像我说的那样,该函数完全按照它应该做的事情。但为什么我会收到这些警告?更具体地说,我如何更改我的代码,以免我得到它们?
解决方案
我能够通过使缓存无效(文件|使缓存无效、无效并重新启动)来解决此问题。感谢莉娜!
推荐阅读
- javascript - 使用 create-react-app 时如何在没有 webpack 依赖的情况下导入节点模块或 JavaScript 文件?
- javascript - Openlayer 5 - 查询样式颜色给出错误结果
- python - 这是 python 装饰器还是 python 属性?
- python - 在 python 的数据集中应用 k-Nearest Neighbors
- python - 根据其他两列熊猫的条件创建一个新列
- asp.net-core-mvc - 在 Partialview o ComponentView Asp.net core 2.2 中使用代码时,ActionLink 和 asp-action 在行表体内不起作用
- jquery - 制作一个可拖动的障碍物=除self之外的所有项目
- django - 以编程方式创建页面对象得到错误 ValidationError 路径和深度字段不能为空白/空
- php - 提交按钮在 Laravel 中什么都不做
- c - 为什么当我在 C 程序的 while 循环中有 2 个 scanf 语句时,在 1 个循环之后只有一个会运行?