08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 14<br />

JavaScript Programming with<br />

<strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong><br />

<strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> offers many extensions to JavaScript, providing object-oriented features<br />

such as namespaces, inheritance, interfaces, enumerations, <strong>and</strong> more. These functionalities<br />

assist you in developing applications by providing more robust <strong>and</strong> structured<br />

language features, making it easier to maintain <strong>and</strong> add new features to your applications.<br />

In this chapter, you’ll look at these extensions to JavaScript, starting with the objectoriented<br />

extensions, <strong>and</strong> then moving into some of the data type extensions, including<br />

arrays, Booleans, <strong>and</strong> dates.<br />

Object-Oriented Extensions to JavaScript<br />

JavaScript, as its name suggests, is a scripting language, <strong>and</strong> thus hasn’t been designed<br />

for higher-order functionality. As Ajax gains traction, requirements for applications are<br />

becoming more <strong>and</strong> more sophisticated, <strong>and</strong> the language in which they are being built<br />

needs to evolve in response.<br />

Thus, <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> has brought about object-oriented extensions to JavaScript to<br />

make the programmer’s life a little easier. Please note that these aren’t changes to the<br />

JavaScript interpreter—they are libraries built into JavaScript itself—so no changes to the<br />

browser are needed to make them work. In this section, you’ll look through some of the<br />

object-oriented features, including classes, namespaces, inheritance, interfaces, enumerations,<br />

<strong>and</strong> reflection.<br />

Using Classes in JavaScript<br />

A class is how you define an object, where an object is an instance of a class. For example,<br />

a car may be a class, but a specific car such as Bob’s 1995 Honda is an object that is<br />

derived from that class, because his Honda is, in fact, a car.<br />

You use a class to define what the properties, methods, <strong>and</strong> events of an object will<br />

be. So, keeping the car example, a property is something that defines an attribute of the<br />

331

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!