haXe2.1到haXe3的变化

来源:互联网 发布:外贸搜索客户软件 编辑:程序博客网 时间:2024/04/29 04:42

见官方文档:http://haxe.org/manual/haxe3

 

捡几个影响比较大的小结如下:

* Zip API现在被移到haxe.zip包,变成完全跨平台的了

* 平台相关的文件操作API被移到sys包中,变成跨平台的了

* 属性的getter和setter命名被标准化了,但仍然向下兼容,见下面例程:

class Foo {
    public var x(get,set) : Int; // haxe2.x中的要写成 public var x(get_x, set_x) : Int;
    function get_x() return 1
    function set_x(v) {
        // ...
        return v;
    }
}

* haXe3不在为属性(properties)自动创建相应的域(filed),如果希望创建field需要显示使用@:isVar元数据,例程如下:

class Foo {
    @:isVar public var x(get,set) : Int;
    function get_x() return x
    function set_x(v) {
        x = v;
        return v;
    }
}

* 在haXe3中只要用单引号来定义字符串就可以自动进行字符串插值(string interpolation)了,比如:

trace('Hello $name, you are $(getAge())');

 

原创粉丝点击