Saltarelle / SaltarelleCompiler

C# to JavaScript compiler – Now http://bridge.net
http://saltarelle-compiler.com
Other
297 stars 74 forks source link

Javascript property getters and setters #299

Open nippur72 opened 10 years ago

nippur72 commented 10 years ago

It would be an improvement if Saltarelle could output true getters and setters for properties (ECMAScript 5) instead of the actual "get_prop" and "set_prop" way. It would be very handy when debugging and when referencing C# code from javascript (e.g. from HTML templates) because of the more natural syntax. There would be also a marginal 4 bytes saving every property access.

If backward compatibility is an issue, there could be a specific [Attribute] to select how to render the class (or the classes in the assembly).

nippur72 commented 10 years ago

this has been already done by @mjrichardson in this fork

erik-kallen commented 10 years ago

Interesting. I had no idea about this fork

erik-kallen commented 9 years ago

If this is implemented, does anyone know how to deal with overrides? In normal case, we can do code gen like below:

class B {
    public virtual int P { get { return 0; } }
}
class C : B {
    public override int P { get { return base.P + 1; } }
}

compiles to

get_P = function() {
    return B.prototype.get_P.call(this) + 1;
}

If we change so the code gen is (equivalent to)

C = {
    get a() { return 0; }
}
B = inherit(C, {
    get a() { return ???; }
});

what can we put instead of ????