【发布时间】:2013-12-10 17:50:29
【问题描述】:
我将一些已编译的 TypeScript(也尝试过使用 CoffeeScript)的输出放入 WebStorm。当我这样做时,JSHint 会为 Snake 函数的内部声明抱怨“'Snake' is already defined”。
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Animal = (function () {
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function (meters) {
alert(this.name + " moved " + meters + "m.");
};
return Animal;
})();
var Snake = (function (_super) {
__extends(Snake, _super);
function Snake(name) { //Warning registered here
_super.call(this, name);
}
Snake.prototype.move = function () {
alert("Slithering...");
_super.prototype.move.call(this, 5);
};
return Snake;
})(Animal);
我可以使用/*jshint -W004 */ 禁用警告,但似乎警告无效,因为我们是在函数范围内。
现在是奇怪的部分。如果我将__extends 调用移到函数声明之后,错误就会消失。
function Snake(name) {
_super.call(this, name);
}
__extends(Snake, _super);
我确实有 2 个问题,但第一个是我的主要问题,我将奖励我的答案。
- 此警告有效吗?
- 将
__extends调用移到函数声明下方会产生什么后果?
【问题讨论】:
标签: javascript jslint jshint module-pattern iife