Closure Compiler Externs - 警告 - 属性 从未定义
Closure Compiler Externs - WARNING - Property never defined on
我正在为 PIXI.js 图书馆准备实习生。我收到以下警告:
js/Test.js:188: WARNING - Property position never defined on PIXI.Sprite
button.position.y = y;
以下是相关的外部定义:
//更新
/**
* @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;
仍然收到相同的警告。
我做错了什么?
当我用 PIXI.DisplayObject.prototype.position;
替换 PIXI.DisplayObject.position;
时,似乎清除了警告。
这是否意味着我应该始终定义 SomeObject.prototype.prop
而不是 SomeObject.prop
?
这突出了静态属性和原型属性之间的区别。
鉴于:
/**
* @constructor
* @param {number=} opt_num
*/
function foo(opt_num) {
if (opt_num !== undefined) {
this.bar = opt_num;
}
}
foo.prototype.bar = 17;
foo.bar = 42;
我们有同名的静态 属性 和原型 属性。但是它们的引用方式不同:
console.log((new foo()).bar); // 17
console.log((new foo(0)).bar); // 0
console.log(foo.bar); // 42
所以在 extern 中,当您在类型上定义属性时 - 您通常希望在原型对象上定义它们:
/** @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);
}
我正在为 PIXI.js 图书馆准备实习生。我收到以下警告:
js/Test.js:188: WARNING - Property position never defined on PIXI.Sprite
button.position.y = y;
以下是相关的外部定义:
//更新
/**
* @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;
仍然收到相同的警告。
我做错了什么?
当我用 PIXI.DisplayObject.prototype.position;
替换 PIXI.DisplayObject.position;
时,似乎清除了警告。
这是否意味着我应该始终定义 SomeObject.prototype.prop
而不是 SomeObject.prop
?
这突出了静态属性和原型属性之间的区别。
鉴于:
/**
* @constructor
* @param {number=} opt_num
*/
function foo(opt_num) {
if (opt_num !== undefined) {
this.bar = opt_num;
}
}
foo.prototype.bar = 17;
foo.bar = 42;
我们有同名的静态 属性 和原型 属性。但是它们的引用方式不同:
console.log((new foo()).bar); // 17
console.log((new foo(0)).bar); // 0
console.log(foo.bar); // 42
所以在 extern 中,当您在类型上定义属性时 - 您通常希望在原型对象上定义它们:
/** @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);
}