Thinking in JavaScript for the C# Developer

I had the great privilege and honor of presenting “Thinking in JavaScript” at the SouthEast Valley .NET Users Group this evening.  All in all, I had a ton of fun.  If anyone else got anything out of it, all the better.

The main point of my discourse was that JavaScript isn’t hard by any means, it just takes an introduction to how it thinks.  Microsoft’s ASP.NET AJAX has made it feel much more like the .net languages we’re used to.  But there are still some inherent differences between a compiled language and a dynamic language.

The main focus of the discussion is these few points:

  • Every object is a Dictionary.  In C#, think of Dictionary<string,object>.
  • Functions assigned into the object’s ‘dictionary’ are like methods.
  • Functions are objects, and can be assigned like variables.  In C#, think of delegates.
  • Every parameter in a function is optional, allowing for uber-easy “function overloading”.

We also covered incredibly cool tools for working with JavaScript:

You can open up MicrosoftAjax.debug.js file by cruising to C: Program Files Microsoft ASP.NET ASP.NET 2.0 AJAX Extensions v1.0.61025 MicrosoftAjaxLibrary System.Web.Extensions 1.0.61025.0 *.debug.js (spaces added for clarity)

And the coolest thing of all – anything built in JavaScript is available for download by choosing “View Source”.  When you publish anything in JavaScript, you don’t publish a compiled assembly, you publish your source.  Thus anything created in JavaScript becomes awesome reference material – bonus!

The slides for this are in Powerpoint 2007 format and available here.  The code we walked through was from Rob Bagby’s webcast series on the ASP.NET AJAX Client Libraries available from his blog: blogs.msdn.com/bags/archive/2007/06/07/latest-asp-net-client-libraries-webcast-sample-code-and-links-to-all-sessions.aspx and blogs.msdn.com/bags/archive/2007/06/07/links-to-remaining-asp-net-ajax-client-libraries-webcasts.aspx

Thanks to all who came – you got some cool swag, and thanks to our sponsor who bought the pizza and showed us just how much we love LINQ. :D

Rob