Page 1 of 1

Intro to JavaScript for ASP AJAX Tutorial on Gotcha's for beginning ASP AJAX Developers Rate Topic: *---- 1 Votes

#1 Shivanry  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 11-July 07

Posted 08 August 2007 - 09:17 AM

Introduction to Javascript
with ASP.NET AJAX 1.0
by Ryan Keeter


Javascript as a dynamic language has many types and a language syntax that is similar to Visual C#. The goal of the ASP .NET AJAX libraries is to create a more object oriented approach to Javascript. There are ways to create inheritance in Javascript, and those are called Prototypes. Also, there are many caveats about Javascript that one must watch out for. These caveats include type coercion that variable scoping.

Javascript Variables

Javascript has some first class citizen variables that are very similar to other languages (Javascript is a C based language after all). For example, the primitive types are :
  • Number
  • String
  • Boolean
  • Function
Anything other than this, such as arrays are just collections of these basic types. One thing though that one must watch out for when declaring these variables is their scope. Scope is the breadth of which a variable is accessible within an application. Javascript, as a dynamic language allows for variables to be produced without being declared, and as such, these variables are immediately given a global scope. Furthermore, any variable that is declared within a function is constrained to the scope of that function and cannot be displayed outside of that function. For example:


function scope()
				 {
					var monkey = "monkey";
				 }
				 
				 if (monkey == "monkey")
					alert("Monkey doesn't exist, an error will be thrown");




If the keyword “var” is not used to define a variable, then it will have a global scope, even if a variable is defined within a function, the variable is accessible outside of the function.

There are many problems that managed language developers face when dealing with equality in Javascript. For example, in Javascript, a string and an integer can be tested for equality and come out true if strict equality is not used. For example:


if(10 == "10")
		 alert("This is true");




If the strict equality and inequality operators are used, then type coercion will not happen. To test for equality using strict equality operators, then use “===”, not “==.” For example of a strict inequality testing:


if(10 !== "10")
		 alert("Using strict inequality operators will not allow type coercion to happen");





Prototypes

Javascript allows for a type of object to be created that looks very similar to the objects one might create in such a language like vb script:


function Person(firstName, lastName)
			{
			 this._firstName = firstName;
			 this._lastName = lastName; 
			 }


Prototyping is the ability in Javascript to add a property or a method to a class (such as person). One must define a function, and then call the class, plus the keyword “prototype” then the name of the class inheritance. Here is a code example:


  function Person(firstName, lastName)
			{
			 this._firstName = firstName;
			 this._lastName = lastName; 
			 }

				function fullName()
				{
				return this._firstName + " " + this._lastName;
				}

				Person.prototype.FullName = fullName;

				var person1 = new Person("Ryan","Keeter");
				 alert(person1.FullName()); //This will return Ryan Keeter
				 




First the object is defined, then another function is defined (fullName). Using the prototype keyword, a new inherited method is added to the Person object, and it is set to equal the function fullName. When the class is called with the new prototype extender, the function fullName is called also, returning the concatenated first and last names.


Conclusion


Understanding how the Javascript engine will define, declare, and coerce variables, along with the knowledge of Prototypes, one has the ability to really get creating making some awesome objects and functions.
With this powerful addition to our arsenal, we are primed and ready to see exactly how ASP .NET AJAX, and the Microsoft AJAX libraries are implemented.

Attached File(s)


This post has been edited by Shivanry: 08 August 2007 - 09:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Intro to JavaScript for ASP AJAX

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 204
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Posted 08 August 2007 - 12:36 PM

this should be submitted into the tutorial section, then the data can be verified and you will be given credit for it.
Was This Post Helpful? 0
  • +
  • -

#3 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Posted 26 August 2007 - 03:47 PM

Hi, I think you should increase the font size, it is not readable at this moment.
Was This Post Helpful? 0
  • +
  • -

#4 joezim007  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 110
  • Joined: 13-September 08

Posted 09 January 2009 - 10:53 PM

That title doesn't make any sense. The only mention to AJAX or ASP.NET is at the end which says, "With this powerful addition to our arsenal, we are primed and ready to see exactly how ASP .NET AJAX, and the Microsoft AJAX libraries are implemented." This is very misleading.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1