企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
>[warning] **定义**:类字段 一个类字段是类中一个变量、属性、或者方法,可以是静态或者非静态的。非静态字段被称为成员字段,所以我们有时候会说,一个静态方法或者一个成员变量。 >[warning] Definition: Class Field > A class field is a variable, property or method of a class which can either be static or nonstatic. Non-static fields are referred to as member fields, so we speak of e.g. a static method or a member variable. 目前我们已经见过一般的类型和Haxe程序如何构造的。这节关于类字段的将对构造部分做出结论,同时通往Haxe的行为部分。这是因为类字段是表达式的家。 > So far we have seen how types and Haxe programs in general are structured. This section about class fields concludes the structural part and at the same time bridges to the behavioral part of Haxe. This is because class fields are the place where expressions (5) are at home. 有三种类字段: > There are three kinds of class fields: * **变量**:一个变量(第4.1节)类字段保存一个某类型的值,可以被读取或者写入。 * **属性**:一个属性(第4.2节)类字段定义一个定制的访问行为,对比如在类之外的,看起来像一个变量字段。 * **方法**:一个方法(第4.3节)是一个函数,可以被调用执行一些代码。 > * Variable: A variable(4.1) class field holds a value of a certain type,which can be read or written. > * Property: A property (4.2) class field defines a custom access behavior for something that, outside the class, looks like a variable field. > * Method: A method (4.3) is a function which can be called to execute code. 严格说,一个变量可以被认为是一个属性带有某个访问修饰符。事实上,Haxe编译器在它们的类型化并不区分变量和属性,但是它们仍然在语法层面分开。 > Strictly speaking, a variable could be considered to be a property with certain access modifiers. Indeed,the Haxe Compiler does not distinguish variables and properties during its typing phase, but they remain separated at syntax level. 关于术语,一个方法是一个(静态或非静态)函数,属于一个类。其他的函数,例如表达式中一个局部函数(第5.11节),不被认为是方法。 > Regarding terminology,a method is a (staticornon-static) function belonging to a class. Other functions, such as a local functions (5.11) in expressions, are not considered methods.