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:
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).
Comments
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.
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.
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());
The World's Most Misunderstood Programming Language
http://javascript.crockford.com/javascript.html
Classical Inheritance in JavaScript
http://javascript.crockford.com/inheritance.html
Arnold Matusz
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.
Thanks a lot for very well-explained and useful article!
This was expanded my skills in JavaScript.
Looks fishy ...
I just picked up "jQuery in Action," and the appendix assumes (too much) familiarity with OO. I found your article in a Google search, and it does a fantastic job explaining principles in a step-by-step fashion. I think I'll now be better able to grasp what jQuery is doing. And I've bookmarked your article for future reference.
Really--thank you.