Suspicious code. The result of the 'getprop' operator is not being used warning GOOGLE CLOSURE

时间:2015-07-13 21:06:55

标签: javascript google-closure-compiler google-closure google-closure-library

I am using google closure and have defined few variables. Only in the constructor am I defining their values. While compiling the the code I get the error

javascript/model/errorLogger.js:42: WARNING - Suspicious code. The result of the 'getprop' operator is not being used.
==> default: [WARNING] model.ErrorLogger.prototype.errors;

This is the code.

goog.provide('model.ErrorLogger');

/**
 * @constructor
 */
model.ErrorLogger = function() {
    this.errors  =[];
    this.errorsHash = {};
}

model.ErrorLogger.prototype.errors;
model.ErrorLogger.prototype.errorsHash;

Why is this warning coming ? Should I mention the typedef annotation ?

1 个答案:

答案 0 :(得分:1)

These lines:

model.ErrorLogger.prototype.errors;
model.ErrorLogger.prototype.errorsHash;

have no effect - you're just referencing the properties without doing anything with them. That's what it's warning you about - it thinks you meant to assign them to something, or pass them to a function, or anything that has some effect.

(Also, those properties won't even exist in that form - it's really not clear what you're trying to do here.)