可以说我有一个像下面这样的课程:
class Types
{
static TypeOne = 1;
static TypeTwo = 2;
static TypeThree = 3;
static TypeFour = 4;
static TypeFive = 5;
public GetNameFromType(type: number) : string
{
switch (type)
{
case Types.TypeOne: return "TypeOne";
case Types.TypeTwo: return "TypeTwo";
case Types.TypeThree: return "TypeThree";
case Types.TypeFour: return "TypeFour";
case Types.TypeFive: return "TypeFive";
default: return "Unknown";
}
}
}
现在,在阅读了一些关于静态类的文档之后,上面的内容似乎应该可以工作。但是我不断收到一条错误消息,说 Types.TypeOne 在当前范围内不存在。
那么我需要做其他事情还是应该这样做?
== 编辑 ==
由于错误,我认为它没有为它输出任何东西,但它似乎有,这是输出:
var Types = (function () {
function Types() { }
Types.TypeOne = 1;
Types.TypeTwo = 2;
Types.TypeThree = 3;
Types.TypeFour = 4;
Types.TypeFive = 5;
Types.TypeSix = 6;
Types.prototype.GetNameFromType = function (type) {
switch(type) {
case AbilityTypes.TypeOne:
return "TypeOne";
case AbilityTypes.TypeTwo:
return "TypeTwo";
case AbilityTypes.TypeThree:
return "TypeThree";
case AbilityTypes.TypeFour:
return "TypeFour";
case AbilityTypes.TypeFive:
return "TypeFive";
case AbilityTypes.TypeSix:
return "TypeSix";
default:
return "Unknown";
}
};
return Types;
})();
这看起来合法,所以也许它正在工作并且只是在抱怨......