The Spec
The Language
The Practice
The Books

Old in the New

Perhaps you’ve heard about the new dynamic language features coming in the next release of C# (C# 3.0). Did you know that JScript .NET already implements some of these features?

Take a look at this new feature that is being offered in C# 3.0:

var o = new {greeting = "Hello", audience ="World", thisIsACoolNewIdea = false};

Notice the new "var" object type. This is interesting because an Ajax developer can tell you that this works for you in JavaScript right now:

var o = {greeting: "Goodbye", audience: "Statics", thisIsntNewEither: true};

Kind of interesting isn’t it.

What about this new C# 3.0 array concept:

var a = new[] {1, 1.3, "Hello", false};

Well, we already got that in JScript .NET too:

var a = [1, 1.3, "Hello", false];

In JavaScript, the subject of “Object Literals” has become very popular. In fact a whole standard has already grown up around the use of object literals for serial communications between the client and server. It’s called JSON (JavaScript Object Notation). I glad that we, as JScript developers, have the ability to use these features today.

One thing you can see from these examples is that C# is insisting on the repeated use of "new". JavaScript makes objects in a more terse fashion. In JavaScript when you use "{}" you automatically get a new object, and when you use "[]" you automatically get a new array.

JScript .NET already has other powerful concepts that, to my knowledge, C# doesn’t plan to implement such as prototyping. Also, we will probably soon see a new release of JavaScript (ECMAScript 4). It will be adding some of the neat features that class-based object languages such as C# have. Although JScript .NET is one of the most advanced versions of JavaScript available today, I look forward to an even better version in the future.

Troy Taft is the Principal Consultant and founder of Troy Taft Consulting, a firm specializing in high value software development. He also authors a free monthly newsletter called Software Matters.

Copyright 2007 Troy Taft All rights reserved, you may print this article for your personal use.