**抽象類型**(第2.8節):
一個抽象類型是一個編譯時構造,在運行時以一個不同的方式表示。這允許給存在的類型一個全新的意義。
> Abstract types (2.8):
> An abstract type is a compile-time construct which is represented in a different way at runtime. This allows giving a whole new meaning to existing types.
**外部類**(第6.2節):
外部類可以被用于以一個類型安全的方式描述目標語言特定的交互。
> Extern classes (6.2):
> Externs can be used to describe target-speci?c interaction in a type-safe manner.
**匿名結構**(第2.5節):
數據可以被簡單的組織為匿名結構,減少小型數據類的必要性。
> Anonymous structures (2.5):
> Data can easily be grouped in anonymous structures, minimizing the necessity of small data classes.
~~~
var point = { x: 0, y: 10 };
point.x += 10;
~~~
**數組推導**(第6.6節):
使用 for 循環和一些邏輯快速創建和填充數組。
> Array Comprehension (6.6):
> Create and populate arrays quickly using for loops and logic.
~~~
var evenNumbers = [ for (i in 0...100) if (i\%2==0) i ];
~~~
**類,接口和繼承**(第2.3節):
Haxe允許用類組織代碼,使其成為一個面向對象語言。通常相關的功能如Jave等語言所支持的,包括繼承和接口。
> Classes, interfaces and inheritance (2.3):
> Haxe allows structuring code in classes, making it an object-oriented language. Common related features known from languages such as Java are supported, including inheritance and interfaces.
**條件編譯**(第6.1節):
條件編譯允許根據編譯參數編譯特定的代碼。這有助于抽象目標語言特定的差異,但是也可以用于其他的目的,如更詳細的調試。
> Conditional compilation (6.1):
> Conditional Compilation allows compiling speci?c code depending on compilation parameters. This is instrumental for abstracting target-speci?c differences,but can also be used for other purposes, such as more detailed debugging.
~~~
\#if js
js.Browser.alert("Hello");
\#elseif sys
Sys.println("Hello");
\#end
~~~
**(廣義的)代數數據類型**(第2.4節):
結構可以通過代數數據類型(ADT)描述,如Haxe語言中的枚舉。除此之外,Haxe支持它們的廣義的變體如GADT。
> (Generalized) Algebraic Data Types (2.4):
> Structure can be expressed through algebraic data types (ADT), which are known as enums in the Haxe Language. Furthermore, Haxe supports their generalized variant known as GADT.
~~~
enum Result {
Success(data:Array<Int>);
UserError(msg:String);
SystemError(msg:String, position:PosInfos);
}
~~~
**內聯調用**(第4.4.2節):
函數可以被設計為內聯,使它們的代碼直接插入調用的位置。通過手動的內聯不用使代碼重復這可以產生顯著的效能提升。
> Inlined calls (4.4.2):
> Functions can be designated as being inline, allowing their code to be inserted at call-site. This can yield signi?cant performance bene?ts with out resorting to code duplication via manual inlining.
**迭代器**(第6.7節):
迭代一組值,例如一個數組的元素,在Haxe中可以很容易的迭代。定制類可以快速的實現迭代器功能來允許迭代。
> Iterators (6.7):
> Iterating over a set of values, e.g. the elements of an array, is very easy in Haxe courtesy of iterators. Custom classes can quickly implement iterator functionality to allow iteration.
~~~
for (i in [1, 2, 3]) {
trace(i);
}
~~~
**局部函數和閉包**(第5.11節):
Haxe中的函數不限于類字段,并可以被聲明為表達式,允許強大的閉包。
> Local functions and closures (5.11):
> Functions in Haxe are not limited to class ?elds and can be declared in expressions as well, allowing powerful closures.
~~~
var buffer = "";
function append(s:String) {
buffer += s;
}
append("foo");
append("bar");
trace(buffer); // foobar
~~~
**元數據**(第6.9節):
添加元數據到字段,類或者表達式。這可以和編譯器、宏,或者運行時的類溝通信息。
> Metadata (6.9):
> Add metadata to ?elds, classes or expressions. This can communicate information to the compiler, macros, or runtime classes.
~~~
class MyClass {
@range(1, 8) var value:Int;
}
trace(haxe.rtti.Meta.getFields(MyClass).value.range); // [1,8]
~~~
**靜態擴展**(第6.3節):
存在的類和其它類型可以被額外的功能來擴展,通過使用靜態擴展。
> Static Extensions (6.3):
> Existing classes and other types can be augmented with additional functionality through using static extensions.
~~~
using StringTools;
" Me & You ".trim().htmlEscape();
~~~
**字符串插值**(第6.5節):
字符串通過一個單引號聲明,可以在當前的上下文訪問變量。
> String Interpolation (6.5):
> Strings declared with a single quotes are able to access variables in the current context.
~~~
trace(’My name is $name and I work in ${job.industry}’);
~~~
**偏函數應用**(第6.8節):
任何函數可以應用為局部的,提供某些參數的值,然后保留其它的作為之后的字段。
> Partial function application (6.8):
> Any function can be applied partially, providing the values of some arguments and leaving the rest to be ?lled in later.
~~~
var map = new haxe.ds.IntMap();
var setToTwelve = map.set.bind(_, 12);
setToTwelve(1);
setToTwelve(2);
~~~
**模式匹配**(第6.4節):
復雜的結構可以被根據模式來匹配,從一個枚舉或者一個結構中提取信息,并對特定的值組合定義特定的操作。
> Pattern Matching (6.4):
> Complex structures can be matched against patterns, extracting information from an enum or a structure and de?ning speci?c operations for speci?c value combination.
~~~
var a = { foo: 12 };
switch (a) {
case { foo: i }: trace(i);
default:
}
~~~
**屬性**(第4.2節):
變量類字段可以被涉及為屬性,通過定制的read和write訪問,可以更精細的訪問控制。
> Properties (4.2):
> Variable class ?elds can be designed as properties with custom read and write access, allowing ?ne grained access control.
~~~
public var color(get,set);
function get_color() {
return element.style.backgroundColor;
}
function set_color(c:String) {
trace(’Setting background of element to $c’);
return element.style.backgroundColor = c;
}
~~~
**訪問控制**(第6.10節):
訪問控制語言特性使用Haxe元數據語法來禁止或者允許訪問類或者字段。
> Access control (6.10):
> The access control language feature uses the Haxe metadata syntax to force or allow access classes or ?elds.
**類型參數、約束和變異**(第3.2節):
類型可以通過類型參數來參數化,使類型化的容器和其它復雜的數據結構可用。類型參數也可以被約束為某些類型并遵守變異規則。
> Type Parameters, Constraints and Variance (3.2):
> Types can be parametrized with type parameters, allowing typed containers and other complex data structures. Type parameters can also be constrained to certain types and respect variance rules.
~~~
class Main<A> {
static function main() {
new Main<String>("foo");
new Main(12); // use type inference
}
function new(a:A) { }
}
~~~
- 空白目錄
- 1.Haxe介紹
- 1.1.Haxe是什么
- 1.2.關于本文檔
- 1.2.1.作者及貢獻者
- 1.2.2.License
- 1.3Hello World
- 1.4.Haxe的歷史
- 2.類型
- 2.1.基本類型
- 2.1.1.數值類型
- 2.1.2.溢出
- 2.1.3.數值運算符
- 2.1.4.Bool類型
- 2.1.5.Void類型
- 2.2.為空性
- 2.2.1.可選參數和為空性
- 2.3.類實例
- 2.3.1.類的構造函數
- 2.3.2.繼承
- 2.3.3.接口
- 2.4.枚舉實例
- 2.4.1.Enum構造函數
- 2.4.2.使用枚舉
- 2.5.匿名結構
- 2.5.1.結構值的JSON形式
- 2.5.2. 結構類型的類記法
- 2.5.3.可選字段
- 2.5.4.性能影響
- 2.6.函數類型
- 2.6.1.可選參數
- 2.6.2.默認值
- 2.7.動態類型
- 2.7.1.Dynamic使用類型參數
- 2.7.2.實現Dynamic
- 2.8.抽象類型
- 2.8.1.隱式類型轉換
- 2.8.2.運算符重載
- 2.8.3.數組訪問
- 2.8.4.選擇函數
- 2.8.5.枚舉抽象類型
- 2.8.6.轉發抽象類型字段
- 2.8.7.核心類型抽象
- 2.9.單形
- 3.類型系統
- 3.1.Typedef
- 3.1.1.擴展
- 3.2.類型參數
- 3.2.1.約束
- 3.3.泛型
- 3.3.1.泛型類型參數解釋
- 3.4.變異
- 3.5.統一
- 3.5.1.類/接口 之間
- 3.5.2.結構子類型化
- 3.5.3.單形
- 3.5.4.函數返回
- 3.5.5.通用基本類型
- 3.6.類型推斷
- 3.6.1.由上而下推斷
- 3.6.2.局限
- 3.7.模塊和路徑
- 3.7.1.模塊子類型
- 3.7.2.Import
- 3.7.3.解析順序
- 4.類字段
- 4.1.變量
- 4.2.屬性
- 4.2.1.常見訪問標識符組合
- 4.2.2.對類型系統的影響
- 4.2.3.getter和setter的規則
- 4.3.方法
- 4.3.1.重寫方法
- 4.3.2.變異和訪問修飾符的影響
- 4.4.訪問修飾符
- 4.4.1.可見性
- 4.4.2.Inline
- 4.4.3.Dynamic
- 4.4.4.Override
- 4.4.5.Static
- 5.表達式
- 5.1.塊
- 5.2.常量
- 5.3.二元操作符
- 5.4.一元操作符
- 5.5.數組聲明
- 5.6.對象聲明
- 5.7.字段訪問
- 5.8.數組訪問
- 5.9.函數調用
- 5.10.var
- 5.11.局部函數
- 5.12.new
- 5.13.for
- 5.14.while
- 5.15.do-while
- 5.16.if
- 5.17.switch
- 5.18.try/catch
- 5.19.return
- 5.20.break
- 5.21.continue
- 5.22.throw
- 5.23.類型轉換
- 5.23.1.不安全轉換
- 5.23.2.安全轉換
- 5.24.類型檢查
- 6.語言特性
- 6.1.條件編譯
- 6.2.Externs
- 6.3.靜態擴展
- 6.3.1.標準庫中的靜態擴展
- 6.4.模式匹配
- 6.4.1.介紹
- 6.4.2.枚舉匹配
- 6.4.3.變量捕獲
- 6.4.4.結構匹配
- 6.4.5.數組匹配
- 6.4.6.Or 模式
- 6.4.7.守護
- 6.4.8.多個值的匹配
- 6.4.9.提取器
- 6.4.10.窮盡性檢查
- 6.4.11.無效的模式檢查
- 6.5.字符串插值
- 6.6.數組推導
- 6.7.迭代器
- 6.8.函數綁定
- 6.9.元數據
- 6.10.訪問控制
- 6.11.內聯構造函數
- 7.編譯器用法
- 7.1.編譯器標記
- 8.編譯器功能
- 8.1.內建編譯器元數據
- 8.2.無用代碼消除
- 8.3.編譯器服務
- 8.3.1.概述
- 8.3.2.字段訪問完成
- 8.3.3.調用參數完成
- 8.3.4.類型路徑完成
- 8.3.5.使用完成
- 8.3.6.位置完成
- 8.3.7.頂級完成
- 8.3.8.完成服務
- 8.4.資源
- 8.4.1.嵌入資源
- 8.4.2.檢索文本資源
- 8.4.3.檢索二進制資源
- 8.4.4.實現細節
- 8.5.運行時類型信息
- 8.5.1.RTTI 結構
- 8.6.靜態分析儀
- 9.宏
- 9.1.宏上下文
- 9.2.參數
- 9.2.1.ExprOf
- 9.2.2.常數表達式
- 9.2.3.其它的參數
- 9.3.具體化
- 9.3.1.表達式具體化
- 9.3.2.類型具體化
- 9.3.3.類具體化
- 9.4.工具
- 9.5.類型構建
- 9.5.1.枚舉構建
- 9.5.2.@:autoBuild
- 9.5.3.@:genericBuild
- 9.6.限制
- 9.6.1.Macro-in-Macro
- 9.6.2.靜態擴展
- 9.6.3.構建順序
- 9.6.4.類型參數
- 9.7.初始化宏
- 10.標準庫
- 10.1.字符串
- 10.2.數據結構
- 10.2.1.數組
- 10.2.2.向量
- 10.2.3.列表
- 10.2.4.GenericStack
- 10.2.5.Map
- 10.2.6.Option
- 10.3.正則表達式
- 10.3.1.匹配
- 10.3.2.分組
- 10.3.3.替換
- 10.3.4.分割
- 10.3.5.Map
- 10.3.6.實現細節
- 10.4.Math
- 10.4.1.特殊數值
- 10.4.2.數學錯誤
- 10.4.3.整數數學
- 10.4.4.擴展
- 10.5.Lambda
- 10.6.模板
- 10.7.反射
- 10.8.序列化
- 10.8.1.格式化序列化
- 10.9.Xml
- 10.9.1.開始使用Xml
- 10.9.2.解析Xml
- 10.9.3.編碼Xml
- 10.10.Json
- 10.10.1.解析JSON
- 10.10.2.編碼JSON
- 10.10.3.實現細節
- 10.11.Input/Output
- 10.12.Sys/sys
- 10.13.遠程處理
- 10.13.1.遠程連接
- 10.13.2.實現細節
- 10.14.單元測試
- 11.Haxelib
- 11.1.Haxe編譯器使用庫
- 11.2.haxelib.json
- 11.2.1.版本控制
- 11.2.2.依賴關系
- 11.3.extraParams.hxml
- 11.4.使用Haxelib
- 12.目標平臺細節
- 12.1.JavaScript
- 12.1.1.開始使用Haxe/JavaScript
- 12.1.2.使用外部JavaScript庫
- 12.1.3.注入原生JavaScript
- 12.1.4.JavaScript untyped函數
- 12.1.5.調試JavaScript
- 12.1.6.JavaScript目標元數據
- 12.1.7.為JavaScript暴露Haxe類
- 12.1.8.使用 require函數加載外部類
- 12.2.Flash
- 12.2.1.開始使用Haxe/Flash
- 12.2.2.嵌入資源
- 12.2.3.使用外部Flash庫
- 12.2.4.Flash目標元數據
- 12.3.Neko
- 12.4.PHP
- 12.4.1.開始使用Haxe/PHP
- 12.4.2.PHP untyped函數
- 12.5.C++
- 12.5.1.Using C++定義
- 12.5.2.Using C++ 指針
- 12.6.Java
- 12.7.C#
- 12.8.Python