My JavaScript Article

My latest OdeToCode article is online: “What ASP.NET Developers Should Know About JavaScript”. The article covers what I personally had to learn before feeling comfortable with modern JavaScript toolkits, frameworks, and libraries. It all boiled down to the following:

  1. Every JavaScript object is a dictionary.
  2. Every JavaScript function is an object.
  3. Every JavaScript object references a prototype object.

Here is the introduction:

JavaScript – It's beat up, put down, shrugged off and kicked around. Cursed by the web browser's inconsistency yet blessed by a pervasive ubiquity -it's a technology many try to disregard even when its potential is something few can ignore. If you want to write an interactive application for the web today, then you'll need some JavaScript code on your side.

This article approaches JavaScript from the perspective of an ASP.NET developer who is comfortable with the paradigms and patterns of either C# or Visual Basic. The article doesn't look at how to use JavaScript from ASP.NET exactly, but it does look at why JavaScript is so different from the two languages we commonly use with the .NET CLR. The article assumes you already know that JavaScript is a loosely-typed language (because you don't have to declare the type of data you store in a variable), and that the syntax is similar to the C family of languages (with charming curly braces and stunningly beautiful semi-colons).

posted on Tuesday, May 08, 2007 9:12 PM by scott

Comments

Wednesday, May 09, 2007 4:28 AM by Francis Norton

# re: My JavaScript Article

Great article, I used to do server-side development in JavaScript many years ago (http://www.ie.com/article.aspx?aid=60&sid=14&id=95) and what you describe is very much what we had to learn, plus the new developments such as JSON and AJAX.
Wednesday, May 09, 2007 9:09 PM by Christopher Steen

# Link Listing - May 9, 2007

Garage Sales and Garage-Sale Quality Code [Via: Scott Hanselman ] MooTools 1.1 Released [Via: Dion Almaer...
Thursday, May 10, 2007 11:09 AM by rodrigo

# re: My JavaScript Article

Great article.. but Visual Studio supports some javascript Intellisense. If you write the following code:
var d= new Date();
in a js file you will get all methods defined in the Date class . That is also true fro every native javascript class. Off course the new javascript intellisense seams to be much more complete.
Sunday, May 13, 2007 3:21 AM by Will

# re: My JavaScript Article

Excellent article. I am proficient in JavaScript and understood the concepts somewhat already, but that was an extremely clear explanation of prototypical inheritance. Thanks :)
Sunday, May 13, 2007 7:40 AM by Andreas

# re: My JavaScript Article

Thanks Scott, very informative and well explained. I learned a lot from it.
Sunday, May 13, 2007 2:28 PM by Will

# re: My JavaScript Article

Hey Scott,
On your private member implementation I am a little concerned about scope. I am not sure if the example was illustrated correctly or now. But for example when declaring a private field in C# you will have global scope within that instance of that class (all methods can see it) however when attempting to actually attempting to test your implementation of private fields each add hoc prototyped method that was added could not see x nor y that were passed through the contructure. Instead they would have to go through the already publicly exposed get and set methods which really does not serve any value at all in that case.
Sunday, May 13, 2007 8:31 PM by scott

# re: My JavaScript Article

Will: that is correct. Since JavaScript doesn't have true "private" members we simulate them with closures. It's not the same behavior as C# (or C++), but not much in JavaScript has the same behavior ;)
Monday, May 14, 2007 11:57 AM by Will

# re: My JavaScript Article

Hey Scott in follow up with Douglas's article I came up with a example which I think better illustrates private fields. At leasts "simulates" closer to the scope behavior in .NET

var obj = function CustomObject()
{
var t = 'test';

CustomObject.prototype.GetVal = function ()
{
return t;
}
}

var newObj = new CustomObject();
alert("Does not have direct access as you can see its undefined: " + newObj._t);
alert("Has access to private field: " + newObj.GetVal());
Monday, May 14, 2007 11:59 AM by Will

# re: My JavaScript Article

type in underscore remove the underscare in the t reference. Still works ;)
Tuesday, May 15, 2007 2:13 AM by Filini

# re: My JavaScript Article

Two other great articles by Douglas Crockford on the same subject:

The World's Most Misunderstood Programming Language
http://javascript.crockford.com/javascript.html

Classical Inheritance in JavaScript
http://javascript.crockford.com/inheritance.html
Wednesday, May 16, 2007 8:38 AM by Justin

# re: My JavaScript Article

I've always found your articles very informative and helpful. This one was no exceptions. Thanks for the very educational reading.
Thursday, May 17, 2007 12:11 PM by Budigelli

# re: My JavaScript Article

Very good article. Nicely explained some of the subtle differences in client side programming and server side for C#, VB.Net developers...
Friday, June 01, 2007 1:57 AM by Dan F

# re: My JavaScript Article

Most excellent article Scott!
Friday, June 01, 2007 9:37 AM by Erik

# re: My JavaScript Article

A great introduction to javascript prototype programming. The next step for most readers is probably trying to get browser events mapped onto the object method, which can be a big pain until you read this: http://www.brockman.se/writing/method-references.html.utf8
Friday, June 01, 2007 4:44 PM by Arnold Matusz

# re: My JavaScript Article

Congratulations, very nice article! Thank you!
Arnold Matusz
Saturday, June 02, 2007 9:01 AM by Ron Krauter

# re: My JavaScript Article

Scott,

Could you explain more on "closures"? You have an inner function that references an outer member. When the outer function goes out of scope, the inner function still has access to those members. This could lead to memory leaks. Is my understanding correct? Thanks in advance.
Saturday, June 02, 2007 10:05 AM by scott

# re: My JavaScript Article

Ron: I will cover that topic in a blog post. Give me about 2 weeks to work it in!
Thursday, June 07, 2007 5:44 AM by Slava

# re: My JavaScript Article

Hi Scott,

Thanks a lot for very well-explained and useful article!
This was expanded my skills in JavaScript.
Thursday, July 31, 2008 9:02 PM by WCF群组博客

# What ASP.NET Developers Should Know About JavaScript

PostedbyscottonTuesday,May08,2007 ThisarticlelooksatJavaScrip...