Archive for April, 2007

Object-Oriented Programming . 73 Using (Submit web site) the Array Notation

Monday, April 30th, 2007

Object-Oriented Programming . 73 Using the Array Notation You can refer to properties and methods using the dot syntax or an array notation. In array notation, square brackets replace the dots. For example, the following expression refers to a.b.d: a[”b”][”d”] You can use the array notation for both properties and methods. The general syntax is: objectReference[”propertyName”] objectReference[”methodName”]([arguments]) It is important to understand this alternative syntax, because you cannot always use the traditional dot syntax. For example, the first character of a property name cannot be a digit when using the dot syntax. When you create an array using the built-in Array object, you can only refer to the elements of the array via the array notation (e.g., myArray[0], myArray[99]). You must always use double quotes when you refer to a property of an object that is not an array. Here are some examples for using the array notation to reference methods and properties: document[”write”](”hello!”) window[”alert”](”howdy!”)//note:alert()==window.alert() Math[”PI”] Sometimes you can only use the array notation. Suppose the variable str holds the string “write”. You can use the following syntax instead of document.write(): document[str]() However, you cannot use document.str() because that is equivalent to document[”str”](). Another situation in which you should use the array notation is when you want to name a property not according to the identifier rules. For example, myObject[”*”] is possible only with the array notation. When you use the array notation, the value in the square brackets should be a string, because the content is evaluated. Object Based Versus Object Oriented Note: This explanation is intended mostly for programmers who are familiar with object-oriented environments. The basic terms of object-oriented programming will not be explained, as they are beyond the scope of this book. Only the most basic differences between JavaScript and full object-oriented languages are introduced here. You will discover many other minor differences as you learn the language. If you are new to object structures, you should skip this explanation altogether. JavaScript is based on a simple object-oriented paradigm. This paradigm is often called object based, as opposed to object oriented. Classes do not exist in JavaScript (all Chapter
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services

72 . Chapter 5 not an object. It (Best web hosting)

Monday, April 30th, 2007

72 . Chapter 5 not an object. It is generally a good practice to avoid naming variables by an object s property or method, at least until you feel comfortable with objects and properties. The output of the statement document.write(a), might be [object create], because that is the object s string equivalent. Methods During execution of a JavaScript script, an object may invoke one or more methods to accomplish a task. As you know, objects consist of both data (properties) and functions that handle the data. These functions are called methods. Methods enable an object to perform different actions, mostly on its own properties. Methods, as previously stated, are simply functions that are part of the object. However, since they are part of the object they have access to the properties of the object including private properties that cannot otherwise be accessed. Most advantages of OOP (object-oriented programming) are associated with methods. JavaScript does not completely support external libraries (other than the SRC attribute of the You can also implement nested with statements. In such cases, several default objects exist simultaneously. The scope (where each one exists) is very simple. Inside a command block associated with a with statement, you can refer to the properties and
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Web hosting domain names - JavaScript Fundamentals . 65 continue Statement The continue

Saturday, April 28th, 2007

JavaScript Fundamentals . 65 continue Statement The continue keyword stops the current iteration of a loop, and continues the execution at the top of the loop. The loop continues to execute until the terminating condition is achieved. The top of the loop is: . The update expression in for loops, such as ++i . The condition expression in while loops Here is a simple example for the usage of the continue statement: var sum=0// will hold the sum of the odd numbers for (vari=1;i<=10; ++i) { if (i%2==0)//1:ifiis even continue // 2: go to the top of the loop sum += i // 3: add i to sum (i is always odd!) } This example adds up every odd integer from 1 to 10. The easiest way to do that is to increase the counter variable by 2 after each pass through the loop, but we wanted to feature the continue statement. The loop in the preceding script segment is quite simple. It executes while the value of i is less than or equal to 10. Therefore, the loop executes 10 times, once for each integer value of i. The first line checks if i is an even number, using a simple modulo operation. If the number is even (that is, i%2 evaluates to 0), the expression i%2 == 0 evaluates to true. In that case, the continue statement on the second line is executed, causing the loop to start from the top, at the update expression. Here is another example using the continue statement: for(i =1; i<= 10;++i) { if (i == 5) continue document.write(i+"") } The output is: 1234678910 The 5 is missing because when i is equal to 5 the loop is sent to the beginning, incrementing i to 6. The continue statement is located before the document.write() statement, so the document.write() method is never invoked when i is 5. with Statement with (object) statement Writing formal addresses to access properties or invoke methods of the same object is often annoying. The with statement establishes a default object for a set of statements. Within the specified set of statements, any property references that do not Chapter
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

Web site traffic - 64 . Chapter 4 for (l = 1;

Saturday, April 28th, 2007

64 . Chapter 4 for (l = 1; l <= 10; l++) { if (l == 5) { continueLooping = false break } if (continueLooping == false) break } if (continueLooping == false) break } if (continueLooping == false) break } if (continueLooping == false) break } For each pass through the loop, continueLooping is evaluated. If it is false, the current loop is terminated. continueLooping is assigned false in the inner loop when the condition l==5 is true, and then each loop terminates in turn. Note that it is extremely important to place the if (continueLooping == false) break statements immediately after the closing brace of the nested loop, so that the loop terminates when the nested loop terminates and no other statements are executed in between. The break statement in JavaScript is very important because it is used to create alternatives to loop statements that do not exist in JavaScript. An important loop type in C++ and Perl is do while. This loop executes a statement as long as the condition is true. Unlike the regular while loop, the condition is evaluated at the end of the loop, so the loop executes once without having tested prior to that. However, JavaScript does not feature such a loop. Once again, it will probably be implemented in a future release of the language. For now, you must come up with a simple alternative using the existing statements. Take a look at the following structure: while (1) { statements if (condition) break } Notice that the preceding script segment is equivalent to the repeat until structure in Pascal, and the do until in Perl, but it doesn t match the do while loop in C++ and Perl. You just have to negate the condition in the following form: while (1) { statements if (!condition) break }
Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services