问题描述
我对吗,TypeScript构造函数中的公共成员在类中是公共的,而私有成员是私有的?
Am I right that public members in a TypeScript constructor are public in the class and that private members are private?
如果是这样,公共成员和财产之间的有效区别是什么?
If so, what is the effective difference between public members and properties?
假定不同之处在于属性可以像c#属性一样工作(也就是说,可以使代码与其访问相关联),为什么要公开 field ,而又没有内部固有的保护使其成为财产?
Assuming that the difference is that properties can act more like c# properties (that is, can have code associated with their access) why would you want to make a field public, without the protections inherent in making it a property?
推荐答案
private创建一个字段,public创建一个属性.
private creates a field and public creates a property.
这不像C#属性,实际上使它成为属性的仅仅是它是公共的.没有访问器.
This is not like a C# property, in fact what makes it a property is just that it is public. There are no accessors.
这篇关于打字稿构造函数中的公共vs私人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!