如何在私人会员和绑定之间选择? [英] How to choose between private member and let binding?

查看:64
本文介绍了如何在私人会员和绑定之间选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写不需要访问同一类的其他成员的私有方法时,如何在私有成员和让绑定之间进行选择?

When writing a private method that has no need to access other members of the same class, how do you choose between private member and let binding?

  • 我倾向于使用私有成员,因为如果需要,可以更轻松地更改可访问性,但是选择时还有其他方面需要牢记吗?
  • 是否将绑定编译为私有成员(这仅是一种样式选择)?

推荐答案

规范的相关部分为

The relevant portion of the spec is section 8.6.2. It states:

用于"let"中声明的值的已编译表示形式 类中的绑定是:

The compiled representation used for values declared in "let" bindings in classes is either:

  • 对象构造函数本地的值(如果值为 不是句法功能,是不可变的,在任何情况下都不会使用 功能或成员).

  • A value that is local to the object constructor (if the value is not a syntactic function, is not mutable and is not used in any function or member).

对应的CLI类型的实例字段(如果值为 不是语法功能,而是用于某些功能或成员).

An instance field in the corresponding CLI type (if the value is not a syntactic function, but is used in some function or member).

对应的CLI类型的成员(如果值是 句法功能).

A member of the corresponding CLI type (if the value is a syntactic function).

也:

两个成员均未使用的非功能let绑定 一个类型或一个函数绑定被优化掉,并成为值 在生成的CLI构造函数中是本地的.同样,功能 绑定表示为实例成员.

Non-function let-bindings that are not used in either the members of a type or a function binding are optimized away and become values that are local to the resulting CLI constructor. Likewise, function bindings are represented as instance members.

我更喜欢将let绑定到私有成员,因为它们更具功能性",即与如何"相比,它们强调什么".编译器负责优化编译形式.

I prefer let bindings to private members because they're more "functional," i.e., they emphasize "what" over "how." The compiler takes care of the optimal compiled form.

这篇关于如何在私人会员和绑定之间选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆