javascript (was Re: Java > Scala -> new thread: GUI for D)

Marco Leise Marco.Leise at gmx.de
Mon Dec 5 01:10:01 PST 2011


Am 04.12.2011, 21:17 Uhr, schrieb Adam D. Ruppe  
<destructionator at gmail.com>:

> Jacob Carlborg Wrote:
> If you like the idea there, but want something a lot more conservative,
> in my html.d (in here:  
> https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff  
> )
> there's now a JavascriptMacroExpander class which pre-processes  
> javascript.
>
> The only build in function it provides right now is foreach() (just  
> because I find
> it's lack to be the easiest thing to take care of...) but the macro  
> system might
> be useful too for certain things.
>
> Again, it's just a preprocessor, so you drop stuff like this into the  
> middle of
> regular js code:
>
> ¤foreach(element; document.querySelectorAll("p")) {
>      element.style.color = "red";
> }
>
> converts to
>
>     var arsd_foreach_loop_temporary_2 = document.querySelectorAll("p");
>     for(var arsd_foreach_loop_counter_1 = 0; arsd_foreach_loop_counter_1  
> < arsd_foreach_loop_temporary_2.length; arsd_foreach_loop_counter_1++) {
>              var element =  
> arsd_foreach_loop_temporary_2[arsd_foreach_loop_counter_1];
>              element.style.color = "red";
>     }

There is also this macro in the JavaScript plugin for Eclipse:

for (var ${index} = 0; ${index} < ${array}.length; ${index}++) {
	var ${array_element} = ${array}[${index}];
	${cursor}
}

This is really one of the largest shortcomings of the language that can  
not be explained with a simple design choice.


More information about the Digitalmars-d mailing list