JavaScript is the "VM" to target for D

Adam D. Ruppe destructionator at gmail.com
Tue Apr 20 20:45:30 PDT 2010


On Tue, Apr 20, 2010 at 11:16:12PM -0400, Eric Poggel wrote:
> I should've also clarified that I'm usually more productive in 
> JavaScript for small projects because it usually takes less code for the 
> same thing, but more so in D for large ones due to the benefits of 
> static typing.

I've been finding D can do small things really effectively too; you
can even write it in a pretty javascriptish style, using closures
returning functions and associative arrays all over the place.

I wrote an implementation of the Javascript DOM in D2 as well:
http://arsdnet.net/dcode/dom.d

To use:
	auto document = new Document(std.file.readText("file.html"));

	auto e = document.getElementById("blah");
	e.attribute = "name";

And you have the whole innerHTML, outerHTML, innerText, etc. etc. too.

Run it through ddoc for more info.


My original idea with it was just have a similar API so I can copy/paste
code between D and JS with minimal modification between the two, but I've
been going wild with it on the server side too, parsing custom extensions
to html to make my output, or stripping useless junk out of html fetched
off the web. Infinitely more useful to me than std.xml, even though I
cared more about looking like the browser than following the standard.


-- 
Adam D. Ruppe
http://arsdnet.net



More information about the Digitalmars-d mailing list