Search code examples
javascriptgoogle-closure-compilergoogle-closuregoogle-closure-library

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


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 ?


Solution

  • 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.)