Open jklein24 opened 9 years ago
@MatrixFrog
Generally, a "this" annotation shouldn't give you access to a protected property unless the function definition is within a class method (a "static", a prototype method). That you don't get a warning in some cases would be a bug. For your case, would defining it as a static would be sufficient?
/** @this {Bar} */
Bar.doThing = function() {
this.doIt();
};
Example:
Thanks, John. That makes sense, but I guess I should take a step back and give a bit more context here because the real problem may be entirely different then. The generated code for a Polymer element is something like:
/**
* @extends {Foo}
* @constructor
*/
var Bar = function() {};
Polymer(/** @lends {Bar.prototype} */ {
/** @this {Bar} */
doThing: function() { this.doIt(); },
...
});
The @this
is really just a workaround for the fact the lends doesn't give the right this context to functions on its own. In this case, these functions really should be "on the prototype". Perhaps the real solution here is to just fix the issues with lends.
Here's a reduction of the problem:
Externs:
Main Module:
This produces the warning: WARNING - Access to protected property doIt of Bar not allowed here. this.doIt();
Some Notes: This doesn't occur if I move the base class into the main module. This doesn't occur if I use Bar.prototype.doThing instead of the @this annotation.