MSDN Magazine - December 2007 - (Page 38) “arguments” is an internal array of JavaScript that returns the list of parameters for a function call. The _validateParams method on the Microsoft AJAX Library Function object is an extension that makes it straightforward for developers to check types and number of method parameters: var e = Function._validateParams( arguments, [{name: ‘value’, type: Number}]); methods named localeFormat and format. You can use them to render a date using the locale culture information: var d = new Date(); d.localeFormat(“dddd, dd MMMM yyyy, hh:mm:ss”); You can grab information about the current locale using the following code: var localShortDate = Sys.CultureInfo.CurrentCulture.dateTimeFormat.ShortDatePattern; var d = new Date(); d.localeFormat(localShortDate); The function takes the argument list and a second array to describe the expected list of arguments. In the preceding code snippet, the method is expected to receive just one numeric argument with the formal name of value. The _validateParams method verifies that the arguments array contains just one numeric element and raises an exception otherwise. Built-In Classes in the Microsoft AJAX Library Now that you know how to create new classes in JavaScript using the Microsoft AJAX Library framework as a basis, let’s explore the system classes built into the framework. Figure 4 describes all the JavaScript classes defined in the Microsoft AJAX Library. The intrinsic JavaScript objects such as Boolean, Date, and Number are extended to incorporate new methods and capabilities. For example, the Date object now includes a couple of new instance Figure 4 Microsoft AJAX Library Built-In Classes Intrinsics Array Boolean Date Error Function Object Number RegExp String Type Sys.UI Namespace Sys.UI.Behavior Sys.UI.Bounds Sys.UI.Control Sys.UI.DomElement Sys.UI.DomEvent Sys.UI.Point Foundation Classes Sys.Component Sys.CultureInfo Sys._Application Sys._Debug Sys._ScriptLoader Description In particular, this code snippet retrieves the short date pattern according to the current culture and uses that to format a date. Where does the Sys.CultureInfo object retrieve locale information? Information relating to the current culture is emitted in the client page whenever the EnableGlobalization property is set to true on the script manager: The script manager writes out a piece of JavaScript code that is then parsed and integrated with the Microsoft AJAX Library runtime using the JavaScriptSerializer class. The Date object also features culture-specific methods to try to build a new date object from arbitrary text. Extends the native Array object with new search methods. Extends the native Boolean object with a parse method. Extends the native Date object with formatting methods. Extends the native Error object to make it similar to a managed exception object. Also exposes static properties to map predefined types of error. Extends the native Function object with delegates and utilities to check method signatures. Extends the native Object object with type information. Extends the native Number object with parsing and formatting methods. Simple wrapper around the native RegExp object. Extends the native String object with formatting methods. Alias for Function where all OOP extensions are grouped. Description Defines the foundation of behaviors used to extend the capabilities of new and existing ASP.NET server controls. Defines a region in the page through top-left-bottom-right parameters. Defines the foundation of Microsoft AJAX Library user interface controls. Wrapper class for a DOM element rendered in the page. Wrapper class for a DOM-level event (such as keystrokes or mouse movements). Defines a point in the page through (x,y) coordinates. Description Defines the foundation of a Microsoft AJAX Library user interface component. Defines culture information. Internal class representing the lifecycle of the current page. Internal class offering debug services. Internal class taking care of loading external scripts. Continued on page 43 38 msdnmagazine Cutting Edge http://ASP.NET
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.