typescript 未指定时隐含哪些访问修饰符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20696932/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 01:10:31  来源:igfitidea点击:

Which access modifiers are implied when not specified?

typescriptaccess-modifiers

提问by Sam

For all of the different concepts that support access modifiers, such as fields, properties, methods and classes, which access modifiers are implied if not specified?

对于所有支持访问修饰符的不同概念,例如字段、属性、方法和类,如果未指定,哪些访问修饰符是隐含的?

回答by basarat

Everything in a classis publicif not specified. Everything in a moduleis private unless exportkeyword is used.

在一切classpublic,如果没有指定。module除非使用export关键字,否则a 中的所有内容都是私有的。

回答by Jens Peters

I do not agree that

我不同意

Everything in a class is public if not specified.

如果未指定,类中的所有内容都是公开的。

Everything is public, even if private is used. Just look at the transpiled code. Private annotated methods will be available public. Only transpiling will throw errors. Both public and private will be converted to <Object>.prototype.funcName

一切都是公开的,即使使用了私有。只需查看转换后的代码即可。私有注释方法将公开可用。只有转译才会抛出错误。公共和私人都将转换为<Object>.prototype.funcName