Using ASP.NET AJAX - Extensions to Existing JavaScript Objects
(Page 3 of 4 )
Chapter 2 described how to add methods to JavaScript base objects like Date. This feature has also been used heavily by the ASP.NET AJAX developers. As a result, JavaScript base types in the following list have been enriched with additional features:
- Array
- Boolean
- Date
- Error
- Number
- Object
- String
None of these extensions alone is worth writing home about, but taken together, they can provide some real value if you write a lot of JavaScript code. Remember that a key idea of any Ajax framework is to dramatically reduce the amount of custom JavaScript code that needs to be written on top of the framework.
Instead of a complete list, we’ll present just one easily written example. The newArray.forEach()method applies a function to each element of a given array.
function Array$forEach(a, fnct){
for (var i = 0; i = a.length; i++) {
if (typeof(a[i]) != "undefined") {
fnct.call(null, a[i], i, a);
}
}
}
However, the built-in ASP.NET AJAXforEach() method saves some typing, a bit of debugging, and a lot of extra maintenance work.
An excellent overview of the new JavaScript object properties are available at no cost as PDF and XPS files. See the “For Further Reading” section at the end of this chapter for details on how to get those files.
Next: ASP.NET AJAX OOP Features for JavaScript >>
More ASP.NET Articles
More By O'Reilly Media
|
This article is excerpted from chapter four of Programming ASP.NET AJAX, written by Christian Wenz (O'Reilly, 2007; ISBN: 0596514247). Check it out today at your favorite bookstore. Buy this book now.
|
|