Hacker News new | past | comments | ask | show | jobs | submit login

So, if one were to use this or something like it, how would you handle DOM interaction? Write JavaScript by hand for that, and have it call out to JSIL-generated code?



Like gecko said, you can use C#'s 'dynamic' feature to grab references to JS objects from the DOM and do late-bound manipulation of them.

Functions can also have their body entirely replaced by a JavaScript expression, and it's done using an attribute so that it doesn't affect how your code runs in native .NET. This is used in parts of the runtime library and in some of the examples, like so:

        [JSReplacement("document.getElementById('speed').innerHTML = $text")]
        static void WriteSpeedText (string text) {
          Debug.WriteLine(text);
        }
You can also directly embed raw JavaScript into function bodies, like this:

        var a = 2;
        var b = 5;
        Verbatim.Expression("print($0 + $1)", a, b);
That allows you to embed particular JavaScript constructs that the compiler won't normally generate, call out to things like jQuery directly, etc. The downside to this is that you've now written something that won't run in any other .NET environment, but you can always wrap it in a JavaScript-only conditional.


Cool, thanks for the explanation.


The DOM is accessible through a dynamic, so you can directly manipulate it from your .NET language of choice.


Good to know, thanks!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: