如何在 Typescript 中将对象定义为 protected 对象或私有(private)对象?
我不能在界面上做(只允许公开), 而且我也不能在类里面这样做,因为下面不起作用。
private options : interface{
collapsible : boolean;
collapsed : boolean;
editable : boolean;
}
有什么提示吗? 谢谢
Zoltán Tamási - 谢谢你的帮助,
在界面中
declare module ICoreModule{
// protected or private
interface IOptions{
initWhenDataReady : boolean;
collapsible : boolean;
collapsed : boolean;
editable : boolean;
}
export interface ICoreScope extends ng.IScope{
sandboxSave : Function;
data : Object;
}
export interface Class extends App.Directive{
$scope : ICoreScope;
$element : ng.IRootElementService;
$attr : ICoreAttr;
$ctrl : ng.IFormController;
}
}
在类里面:
protected options : ICoreModule.IOptions = <ICoreModule.IOptions>{
initWhenDataReady : true,
collapsible : true,
collapsed : true,
editable : true
};
最佳答案
如果您在模块
中定义了一个类或接口(interface),您可以选择是否要export
它,使用export
> 关键字。
如果一个类或接口(interface)没有导出,那么它只在声明模块内可见。
但是,如果在导出类的任何公共(public)成员、方法等中使用了非导出类或接口(interface),那么您将遇到编译错误,然后您必须将其导出。
关于javascript - typescript -对象作为私有(private)或 protected ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33230854/