How do I Write that In JavaScript?

A comment was left in response to Master Detail in Silverlight 2 asking "Any hint how to create such a sample with Java Script instead C#?"

I thought the answer was important enough to post to the blog in general…

MultiLanguageTwo points about your question. The first is whether you are asking if one can write this same program in JavaScript in Silverlight 2 (answer: yes) or you are asking if one can write the same program in Silverlight 1.0 (which only uses Javascript) (answer: depends).

Second point is that there are a number of languages that SL2 supports: IronRuby, JavaScript, VB, C#, etc., and (frankly) it won't be possible for me to illustrate all of them (or even most of them) in these examples, but it shouldn't be terribly hard to translate the logic from one language to another because the code is pretty simple and the Silverlight documentation shows the syntax for each event, method and property in the various languages.

While it is true that Silverlight 2 supports JavaScript, it is also true that C# supports language features that simply are not available in Javascript such as generics (ListOf<Books>) and true classes and objects. Translating my examples from C# to (e.g.,) VB is trivial, but translating to JavaScript is more of a challenge.

Which brings me to my final point, which is that I honestly can't imagine why you'd want to do this in Javascript; the code will be slower, harder to maintain and harder to create.

If you'll pardon what may sound rude and even arrogant, I think you'll be a lot happier if you take the opportunity to "step up" to managed code (see, for example, Programming C# 3.0, 5th Edition by my favorite author) which will not only enhance your Silverlight experience, but will bring you nicely into the entire spectrum of .NET programming from ASP.NET, ASP.NET/AJAX through WPF, WCF, Workflow, etc.

Programming C# 3.0 (Programming)
by Jesse Liberty, Donald Xie

Read more about this title…

You'll love it. I tried it in 2000 and never looked back.








About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen Pluralsight & LinkedIn Learning courses. He was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP and a Microsoft MVP.
This entry was posted in z Silverlight Archives and tagged . Bookmark the permalink.