dorba / blade

The core tools for Blade rich client development.
89 stars 14 forks source link

Array initialization happening after calling the base constructor #12

Closed Ventajou closed 12 years ago

Ventajou commented 12 years ago

Consider the following:

    class BaseClass
    {
        public virtual string[] Foo { get { return new[] { "Base" }; } }

        public BaseClass()
        {
            console.log(Foo);
        }
    }

    class ChildClass : BaseClass
    {
        private string[] _bar = new string[] { "Child" };
        public override string[] Foo { get { return _bar; } }

        public ChildClass()
            : base()
        { }
    }

The compiled JavaScript will actually initialize the array out of order, which is inconsistent with how c# works:

ChildClass = (function() {
    Blade.derive(ChildClass, BaseClass);
    var $base = BaseClass.prototype;
    function ChildClass() {
        $base.constructor.call(this);
        this._bar = ['Child'];
    }
    var p = ChildClass.prototype;
    p.get_Foo = function() {
        return this._bar;
    };
    return ChildClass;
})();
dorba commented 12 years ago

Fixed by commit 790c401ed4c8aed068d4faba142132f601229a96