简体   繁体   English

关闭编译器错误:JSC_NOT_A_CONSTRUCTOR

[英]Closure Compiler Error: JSC_NOT_A_CONSTRUCTOR

I was playing around with closure compiler and put in this code: 我正在玩闭包编译器,并输入以下代码:

var obj = (function() {
  function H(a) {
    this.a = a
  }
  var h = new H(1);
  h.b=1
  return h
})();

I wanted to see if it would convert it to this: 我想看看它是否会将其转换为:

var obj = (function() {
  function H(a) {
    this.a = a;
    this.b = 1
  }
  var h = new H(1);
  return h;
})();

But instead I got this error 但是我却得到了这个错误
JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 6 character 8 var h = new H(1);

What am I doing wrong? 我究竟做错了什么?

You have to tell CC that the function is a constructor via @constructor : 您必须通过@constructor告诉CC该函数是构造@constructor

/**
 * Makes an H.
 * @constructor
 */
function H() {
  ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JSC_NOT_FUNCTION_TYPE谷歌关闭编译器 - JSC_NOT_FUNCTION_TYPE google closure compiler 使用 gulp 闭包编译器插件时出现 JSC_REDECLARED_VARIABLE_ERROR - JSC_REDECLARED_VARIABLE_ERROR when using gulp closure compiler plugin 错误 - [JSC_UNDEFINED_VARIABLE] 变量 previousPage 未声明 - Google Closure Compiler - ERROR - [JSC_UNDEFINED_VARIABLE] variable previousPage is undeclared - Google Closure Compiler Google Closure Compiler,如何优雅地处理JSC_INEXISTENT_PROPERTY? - Google Closure Compiler, how to handle JSC_INEXISTENT_PROPERTY gracefully? Google Closure编译器,处理JSC_INEXISTENT_PROPERTY警告 - Google Closure Compiler, Handling JSC_INEXISTENT_PROPERTY warning Closure编译器:@enum,属性崩溃和JSC_UNSAFE_NAMESPACE - Closure Compiler: @enum, property collapsing and JSC_UNSAFE_NAMESPACE Google闭包编译器,带有mixin / extend的JSC_INEXISTENT_PROPERTY问题 - Google closure compiler, JSC_INEXISTENT_PROPERTY issue with mixin/extend Google Closure编译器中的JSC_TYPE_MISMATCH警告 - JSC_TYPE_MISMATCH warning in Google Closure Compiler 使用Google Closure编译器,webpack和Firebase JS SDK编译js时发生JSC_NON_GLOBAL_DEFINE_INIT_ERROR - JSC_NON_GLOBAL_DEFINE_INIT_ERROR occurs when compiling js with Google Closure Compiler, webpack, and Firebase JS SDK Closure编译器(soy)-[JSC_BAD_JSDOC_ANNOTATION]解析错误。 非法使用未知的JSDoc标签“ consistentIdGenerator” - Closure Compiler (soy) - [JSC_BAD_JSDOC_ANNOTATION] Parse error. illegal use of unknown JSDoc tag “consistentIdGenerator”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM