什么是JSC_MULTIPLE_VAR_DEF?

pim*_*ing 2 javascript google-closure-compiler

我花了半个小时找到这个问题的答案.将它和答案一起发布在这里,希望能节省半个小时.

编译此代码时

"use strict";
/**
 * These are the flower and the instrument used in the code below.
 */
var flower, instrument;
Run Code Online (Sandbox Code Playgroud)

Closure Compiler给了我们这个警告

JSC_MULTIPLE_VAR_DEF: declaration of multiple variables with shared type information at line 6 character 0
var flower, instrument;
^
Run Code Online (Sandbox Code Playgroud)

这个含糊的警告意味着什么?

Joh*_*ohn 5

您应该为此提交错误:http: //code.google.com/p/closure-compiler/issues/list

它应该只在你使用@type时抱怨.即使这样,我也不清楚这是否合适.看来我应该能够做到这一点:

/** @type {string} */
var a,b,c;  // all strings
Run Code Online (Sandbox Code Playgroud)

  • 这让我感到很恼火. (2认同)