Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to play the role of Javascript with any other language like C#? One way came up in my head is, having silverlight installed, using C# instead of Javascript for all the client side scripting (Though C# is not a scripting language). Is it possible?

I am not talking about something like GWT(Java) or Script#(C#). Probably the question can be stated as- "With silverlight installed, can I do everything supported by Javascript(like DOM manipulation etc) with C#?" Hope it's clearer.

share|improve this question

closed as too broad by Scant Roger, Ixrec, GlenH7, MichaelT, Bart van Ingen Schenau Dec 26 '15 at 20:12

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Why would you want to do this? – Darknight Mar 29 '11 at 10:28
Comfort of working with known/expertise language – Aditya P Mar 30 '11 at 5:05
C# and Javascript share the same C style; so your already starting off on a good footing... – Darknight Mar 30 '11 at 12:29
...and then you stumble horribly on things like block scope, hoisting or prototype inheritance. C-like syntax is the worst thing that happened to js. – scrwtp Sep 24 '12 at 10:47
I love both C# and JavaScript, and I agree with scrwtp. JavaScript should have used a completely different syntax than the one it did. There's very little in common between C# and JS besides the "(){};" characters. – Graham Sep 24 '12 at 12:20

You have a few options for using other languages in place of Javascript:

  • You can use any language that you can compile to javascript (like coffeescript, Java via GWT, etc),
  • You can use any language that you can interpret using a javascript interpreter (many templating languages use this technique),
  • You could use nativeclient to deploy your language (I'm unsure of the support for DOM interaction from nativeclient, so I'm not sure how viable this is), but in any case the take-up will be small,
  • You could add support for another language into a browser and struggle with next to no users.

Only the first two techniques are really to be considered. If you detest javascript so much, take a look at coffeescript.

share|improve this answer
It's hard to debug in the browser anything that isn't javascript. You can't use debugger in you coffeescript. If there is error in your coffeescript compiled to javascript, you may have trouble to find out to which line it corresponds in your coffeescript sources. The solution is something called "map sources", but it's not yet implemented in any of browsers. – Czarek Tomczak Sep 24 '12 at 7:31

One way to do this is to compile code in language <put language name here> to Javascript. This has the advantage that the compiled code can run wherever Javascript can run.

Emscripten can be used for languages for which there is compiler(s) which produce LLVM bytecode (C and C++ are just 2 of these).

Emscripten works by generating Javascript code from LLVM bytecodes.

share|improve this answer

Intresting question!

A bit of googling no offence :) found jsc, which lets you port C# to javascript.

What is jsc?

jsc is a decompiler or a cross compiler if you will. It is not a source-code parser nor an IDE. It is a command line utility like any other compiler. jsc was originally an anagram for csharp to javascript.

I need to do some web work and I know very little javascript, so I'll be trying this out.

share|improve this answer
You can check Script#- – Gulshan Mar 29 '11 at 10:50

If you are into python, you can use Pyjamas .

Currently project name is pyjs. This is the description of the project:

pyjs is a Rich Internet Application (RIA) Development Platform for both Web and Desktop. With pyjs you can write your JavaScript-powered web applications entirely in Python.

pyjs contains a Python-to-JavaScript compiler, an AJAX framework and a Widget Set API. pyjs started life as a Python port of Google Web Toolkit, the Java-to-JavaScript compiler.

Interesting part for the OP will be the "python-to-javascript compiler".

share|improve this answer

With Silverlight installed, your client is coded in C# right?

You don't need DOM manipulation if you use Silverlight - Silverlight is a plugin that works inside the browser (similar to flash) and is a separate runtime. You can do things similar to DOM manipulations (for e.g. showing/hiding fields, animations, etc) but all this will now be done in XAML and C#, not with HTML and Javascript.

Hope that clarifies - a silverlight application has no need for Javascript features.

share|improve this answer
I think he means to still use HTML, but to have an invisible Silverlight object doing DOM manipulation. – Chris Sep 24 '12 at 13:37
why.. why... whyyyyy!!! – Roopesh Shenoy Sep 25 '12 at 14:23

Unless all the major browsers implemented the language, or a plugin was provided for all the major browsers and you managed to convince your users to install it, then no, Javascript is the only option.

But really, what's wrong with Javascript? As a language, it's actually really nice and quite powerful. The biggest "problem" with Javascript is differing implementations of the DOM across browsers, and introducing another language isn't going to solve that problem.

share|improve this answer
using jQuery will solve many of the problems of the DOM. – Zachary K Mar 29 '11 at 9:38
@Zachary: Right, but jQuery doesn't really have anything to do with introducing a new client-side language... – Dean Harding Mar 29 '11 at 9:42
no, but it does make Javascript a lot more enjoyable to use. – Zachary K Mar 29 '11 at 10:18

GWT is using Java to generate JavaScript code, so I think something similar would be possible with C#. However you probably can't just replace JavaScript on client side with other (scripting) language.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.