最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - `Cannot instantiate non-constructior` Closure Compiler warning? - Stack Overflow

programmeradmin3浏览0评论

Dear folks, what should I do with these error warnings that Closure Compiler outputs? Thank you very much for your ideas and code improtements on this particular type of error:

  1. JSC_WRONG_ARGUMENT_COUNT: Function parseInt: called with 1 argument(s). Function requires at least 2 argument(s) and no more than 2 argument(s). at line 593 character 12
    if (parseInt(jQuery.browser.version) < 7) {

  2. JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 708 character 15
    lightbox = new Lightbox(this, opts.lightbox);

  3. JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 1265 character 19
    var scroller = new Scroller($(this), opts);

Dear folks, what should I do with these error warnings that Closure Compiler outputs? Thank you very much for your ideas and code improtements on this particular type of error:

  1. JSC_WRONG_ARGUMENT_COUNT: Function parseInt: called with 1 argument(s). Function requires at least 2 argument(s) and no more than 2 argument(s). at line 593 character 12
    if (parseInt(jQuery.browser.version) < 7) {

  2. JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 708 character 15
    lightbox = new Lightbox(this, opts.lightbox);

  3. JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 1265 character 19
    var scroller = new Scroller($(this), opts);

Share Improve this question edited Oct 2, 2024 at 18:42 Jonas 129k101 gold badges326 silver badges405 bronze badges asked Mar 14, 2011 at 16:32 SamSam 15.5k25 gold badges96 silver badges153 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 19

Number 1:
This warning means that you passed-in the wrong number of arguments in a function call.

Here is a better explanation

Number 2 & 3:
The compiler expects all constructors to be marked with the JSDoc tag @constructor, like this:

/**
 * @constructor
 */
function MyClass() {
  this.foo = 'bar';
}
var obj = new MyClass();
alert(obj.foo);

Here is a better explanation.

For the first one, it wants you to pass two parameters to parseInt: value and radix. For 10-based numbers (which is your case), you need (don't really need but it wants you to) call

parseInt(jQuery.browser.version, 10)
发布评论

评论列表(0)

  1. 暂无评论