typescript 在一类打字稿中扩展和实现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29336496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
extend and implement in one class typescript
提问by Everton Santos
Can i do this on typescript?
我可以在打字稿上做到这一点吗?
export interface IMyInterface {
doSomething():void;
}
export class MyBaseClass {
myBaseClassHasProperty:string;
constructor(){
this.myBaseClassHasProperty = 'some value';
}
myBaseClassHasMethods():void{
console.log(this.myBaseClassHasProperty);
}
}
export class MyClass extends MyBaseClass implements IMyInterface {
constructor(){
super();
}
doSomething():void{
this.myBaseClassHasMethods();
}
}
in runtime i get this
在运行时我得到这个
Uncaught ReferenceError: MyBaseClass is not defined
未捕获的 ReferenceError:未定义 MyBaseClass
采纳答案by basarat
in runtime i get this
Uncaught ReferenceError: MyBaseClass is not defined
在运行时我得到这个
Uncaught ReferenceError: MyBaseClass is not defined
Yes you can do that. The code you posted will work fine.
是的,你可以这样做。您发布的代码将正常工作。
However I suspect in your actual codeyou have it split across multiple files and MyBaseClass
is not executedbefore the code for MyClass
.
但是,我怀疑在您的实际代码中,您将其拆分为多个文件,MyBaseClass
并且不会在MyClass
.
Fix JavaScript ordering or use external modules to have the ordering determined by the module loader.
修复 JavaScript 排序或使用外部模块让模块加载器确定排序。