-
Book Overview & Buying
-
Table Of Contents
Microsoft AJAX Library Essentials: Client-side ASP.NET AJAX 1.0 Explained
Objects and classes are implemented differently in JavaScript than in languages such as C#, VB.NET, Java, or C++. However, when it comes to using them, you’ll feel on familiar ground. You create objects using the new operator, and you call their methods, or access their fields using the syntax you already know from C#. Here are a few examples of creating objects in JavaScript:
// create a generic object var obj = new Object(); // create a Date object var oToday = new Date(); // create an Array object with 3 elements var oMyList = new Array(3); // create an empty String object var oMyString = new String();
Object creation is, however, the only significant similarity between JavaScript objects and those of “typical” OOP languages. The upcoming JavaScript 2.0 will reduce the differences by introducing the concept of classes, private members, and so on, but until then we have to learn how to live without them.
Objects in JavaScript have the following particularities...
Change the font size
Change margin width
Change background colour