D to Javascript converter (a hacked up dmd)

Piotr Szturmaj bncrbme at jadamspam.pl
Tue Feb 28 19:24:23 PST 2012


Adam D. Ruppe wrote:
> The reason it didn't work before wasn't just dollar, but also
> ref params. This was a bit of a pain.. without pointers, how
> can I implement this?
>
> After thinking on it for almost an hour, I decided on passing
> lambdas instead:
>
> void a(ref b) { b = 10; }
>
> int c = 5;
> a(c);
> assert(c == 10);
>
>
> The JS looks like this:
>
> function a(b) { b(10); }
> var c = 5;
> a(function(set) { if(typeof set != "undefined") c = set; return c; });
> c == 5 || _d_assert();

What about passing values within object?

function a(b) { b.value = 10; }
var c = 5;
var wrapper = { value: c };
a(wrapper);
c = wrapper.value;


More information about the Digitalmars-d-announce mailing list