Closing External Compiler Components - WARNING - A property that is never defined on

I am preparing externs for the PIXI.js. library I get the following warning:

js/Test.js:188: WARNING - Property position never defined on PIXI.Sprite button.position.y = y; 

Here are the relevant extern definitions:

// UPDATE

 /** * @constructor * @extends {PIXI.Container} * @param {PIXI.Texture} texture */ PIXI.Sprite = function(texture){}; /** * @constructor * @extends {PIXI.DisplayObject} */ PIXI.Container = function(){}; /** * @constructor * @extends {PIXI.EventEmitter} */ PIXI.DisplayObject = function(){}; /** * @type {PIXI.Point} */ PIXI.DisplayObject.position; 

A warning still appears.

What am I doing wrong?

When I replace PIXI.DisplayObject.position; at PIXI.DisplayObject.prototype.position; That seems to clear the warning.

Does this mean that I should always define SomeObject.prototype.prop , and not SomeObject.prop ?

+6
source share
1 answer

This emphasizes the difference between static and prototype properties.

Given:

 /** * @constructor * @param {number=} opt_num */ function foo(opt_num) { if (opt_num !== undefined) { this.bar = opt_num; } } foo.prototype.bar = 17; foo.bar = 42; 

We have both a static property and a prototype property with the same name. However, they refer in different ways:

 console.log((new foo()).bar); // 17 console.log((new foo(0)).bar); // 0 console.log(foo.bar); // 42 

So, in the external, when you define properties for a type - you usually want to define them on a prototype object:

 /** @param {foo} obj_foo */ function log(obj_foo) { // This is an instance of "foo". // The "bar" property references prototype or instance // properties - not static properties. console.log(obj_foo.bar); // Static properties can only be referenced by the full namespace console.log(foo.bar); } 
+1
source

All Articles