Archive for July, 2007

JavaScript Programmer’s Reference Cross-references: (Simple web server) ECMA 262 edition 2

Friday, July 27th, 2007

JavaScript Programmer’s Reference Cross-references: ECMA 262 edition 2 section 7.6 ECMA 262 edition 2 section 11.2 ECMA 262 edition 3 section 7.7 Wrox Instant JavaScript ISBN 1-861001-27-4 page 16 Wrox Instant JavaScript ISBN 1-861001-27-4 page 32 Wrox Instant JavaScript ISBN 1-861001-27-4 page 33 Array literal (Declaration) A means of creating and initializing an array at once. Availability: ECMAScript edition 3 JavaScript 1.3 JScript 5.0 Internet Explorer 5.0 Netscape 4.7 Property/method value type: Array object JavaScript syntax: -[ anElement, … ] Argument list: anElement An element to be stored in the array JavaScript version 1.2 introduces the capability of assigning values to an array as it is created and building the array without first using a constructor. Now array construction can also be nested to create multi-dimensional arrays. The result is an array containing the elements defined by the literal expression. Warnings: . Netscape 4 does not mind an extra trailing comma (as per the C language convention). To force an undefined element to be assigned to the end of the array, you must place two trailing commas. . MSIE adds an undefined element for each trailing comma. This means that MSIE creates arrays that are one item longer than Netscape does if there is a trailing comma. . Some revisions of Netscape exhibit a further problem in that a single numeric value in the square brackets is interpreted as an array length value. This is consistent with the Array() constructor but is not correct in this context. You can place a pair of trailing commas there to fix this at the expense of some wasted array items that contain undefined values. This is not a problem on all versions and may be encountered only rarely now.

Managed web hosting - A Array index delimiter ([ ]) (Delimiter)

Thursday, July 26th, 2007

A Array index delimiter ([ ]) (Delimiter) But in JavaScript we can at least manage this: multiArray[1][2] This is close enough that most programmers will be able to cope with it quite happily. Another alternative way to do this is to use a single dimensional array, but calculate the indices. For example to make a 5 x 5 array, you would create a single dimensional array that is 25 elements long. Then to reach the rows you use the row number and multiply the value by 5 before adding the column number to access the desired cell. You need to be careful though because if you have an ‘off-by-one’ error, it all goes wrong. Warnings: . Be aware that your script is referring to array elements starting at zero. You can get subtle ‘off-byone’ errors if you assume that the array begins at item 1. . In Netscape 2.02, the length property of an array cannot be relied on to hold the right value. . You should avoid putting spaces into associative names because it introduces a property whose name cannot be reached other than via an array index. Not all implementations will trap this error situation. A property name is an identifier and identifier names cannot contain spaces so it should throw an exception. Example code: See also: Array object, Array.length, Associativity, Multi-dimensional arrays, Off by one errors, Operator Precedence, Postfix operator, Property name

Java web server - JavaScript Programmer’s Reference Array index delimiter ([ ])

Thursday, July 26th, 2007

JavaScript Programmer’s Reference Array index delimiter ([ ]) (Delimiter) Access elements of an array with this delimiter. the array length Array elements are indexed by selecting them numerically within the set of elements contained in the array. The length property of an array indicates how many indexable locations there are. Array elements begin with the zeroth item. Storing values into indexes that are higher than the current value of the length property will automatically extend the array and reset the length property. An array with only one entry in the 100th element (index value 99) is very sparsely populated but still should report a length value of 100. In Netscape, referencing the array with no element delimiters will yield a comma-separated list of the contents of the array. So this: Availability: ECMAScript edition 2 JavaScript 1.1 JScript 3.0 Internet Explorer 4.0 Netscape 3.0 Netscape Enterprise Server 2.0 Opera 3.0 Property/method value type: Depends on array content JavaScript syntax: -myArray[anIndex] Argument list: anIndex A legal index value into the array, not greater than myArray = new Array(6);myArray[0] = 0;myArray[1] = “XXX”;myArray[2] = 0;myArray[3] = “XXX”;myArray[4] = 0;myArray[5] = “XXX”;document.write(myArray); Yields this when executed: 0,XXX,0,XXX,0,XXX Accessing properties of an object by name simply requires the name to be added to the object reference with a dot separator between them. Numeric values cannot be used in this way. You must use a string to name the array element when it is assigned. The associativity is left to right. Refer to the operator precedence topic for details of execution order. Although JavaScript does not properly support multi-dimensional arrays, you can simulate them by storing references to one array in the elements of another. You need to create a separate array for each row and then one master array to arrange them into a column. True multi-dimensional arrays would use a notation like this: multiArray[1,2]

Web hosting account - A Arithmetic type (Definition) Warnings: . Applying

Wednesday, July 25th, 2007

A Arithmetic type (Definition) Warnings: . Applying some operators causes a strange degenerative effect in the accuracy. On the Macintosh in MSIE 5.0 and in Netscape 4, the following loop generates a very strange sequence of numbers that are quite erroneous: for(myEnum = 1.5; myEnum > -2; myEnum -= 0.1) { document.write(myEnum + “
“); } . There are some very odd and subtle mathematical errors in the arithmetic handling within the Macintosh platform, and it surely must be the platform since the same behavior is found on both MSIE and Netscape. Additive operator, Expression, Mathematics, Multiplicative operator, Postfix operator, Prefix decrement (–), Prefix increment (++), Prefix operator, Remainder (%), Remainder then assign (%=), Subtract (-), Subtract then assign (-=), Type conversion See also: Cross-references: Wrox Instant JavaScript page 18 Arithmetic type (Definition) A subset of the native types concerned with numeric values. In the C language, programmers need to be aware of the many and various types of numeric value. JavaScript hides a great deal of this complexity by presenting a Number data type. However, internally it still uses 32 bit integer values, 16 bit integer values, signed and unsigned integers, and floating-point values. Arithmetic type values are used with arithmetic operators to build arithmetic expressions. Characters are maintained as single character strings, but can be represented numerically by converting them to their Unicode code point value using the method String.charCodeAt(). You can convert back again using the String.fromCharCode() method. See also: String.charCodeAt(), String.fromCharCode()

JavaScript Programmer’s Reference In (Web hosting domain) general, the first argument

Wednesday, July 25th, 2007

JavaScript Programmer’s Reference In general, the first argument is the name of the script or program being executed. To establish the length of the argv array, you can inspect the argc value. The values passed in the argvarray are likely to be presented as strings, although they may be automatically cast to number, Boolean or other types without you needing to perform any type conversion yourself. Warnings: . If you call one script from another, the command-line arguments that were used to invoke the original script may not be propagated unless your calling script makes some arrangements to pass in the arguments it was given. Each script is likely to run in a separate execution context. See also: argc parameter, Execution context, Execution environment, Host environment, Host object, main() function Arithmetic constant (Definition) A constant derived from arithmetic (numeric) values. An arithmetic constant is derived from one of the following: . Unicode character code value of a character constant . Enumeration constant . Floating-point constant . Integer constant . Math object property . Number object property . Global object property Constant expression, Floating-point constant, Infinity, Integer constant, Math.E, Math.LN10, Math.LN2, Math.LOG10E, Math.LOG2E, Math.PI, Math.SQRT1_2, Math.SQRT2, NaN, Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY See also: Arithmetic operator (Definition) An operator that works with numeric operands. The collection of arithmetic operators includes the operators in the following categories: . Additive operator . Multiplicative operator . Postfix operator . Prefix operator

Web site optimization - A arguments[] (Collection) Property attributes: ReadOnly, DontEnum.

Tuesday, July 24th, 2007

A arguments[] (Collection) Property attributes: ReadOnly, DontEnum. Cross-references: Wrox Instant JavaScript, ISBN 1-861001-27-4 page 27 myResult = myFunction(aaa, bbb, ccc, ddd); Arguments array length aaa bbb ccc ddd arguments[] (Collection) A property that is available inside a function to access its Arguments object. ECMAScript edition 2 JavaScript 1.1 JScript 5.5 Internet Explorer 5.5 Netscape 3.0 Availability: This property is only defined within a function body in a web browser. However, some implementations may provide external arguments via this property. See also: Arguments object, Function arguments, Function.arguments[] Property attributes: ReadOnly. argv parameter (Definition) A command-line argument collection. Since JavaScript can be used in many environments, it is possible that in a server-side application you will have access to the command-line arguments. If that is the case, then it is likely that you will have an argv property, which contains the argument values.

JavaScript Programmer’s Reference Property attributes: DontEnum. Arguments.length (Property)

Tuesday, July 24th, 2007

JavaScript Programmer’s Reference Property attributes: DontEnum. Arguments.length (Property) The number of arguments passed to a function dictates the length of the array to hold them. Availability: JavaScript 1.1 JScript 5.5 Internet Explorer 5.5 Netscape 3.0 Property/method value type: Number primitive JavaScript syntax: -myArguments.length The number of arguments passed to a function when it is called. The length property of the Arguments object can be inspected or used in an enumeration loop to access each argument in turn. Even if no placeholder arguments are specified, you can still call a function and pass as many arguments to it as you like. They will be assembled into an array that you can manipulate in the way you would normally operate on any other array. You can build enumerators to process all the elements and do something with them. You can compare this value with the arity property of the owner function object. This will allow you to determine whether the correct number of arguments was passed. Example code: Argument, Argument list, Arguments object, Collection.length, Function.arguments[], Function.arity, Function.length See also:

A Arguments.caller (Property) Warnings: (Frontpage web hosting) . This property

Monday, July 23rd, 2007

A Arguments.caller (Property) Warnings: . This property is incorrectly implemented in Netscape 3, which returned a reference to the calling function and not its arguments. Since it works correctly in Netscape 4, you should consider that it is only available there. . The example shown below did not work correctly on Netscape 6.0 at time of writing. . This is not part of the ECMA standard and is at some risk of becoming deprecated and removed in later versions. In fact, it is deprecated as of JavaScript version 1.3 and should not be used in new projects. . It is recommended that you do not build this into functional deployed applications, although the risks involved with using it for debugging are small. Example code: See also: Arguments object, Arguments.callee, Debugging client side, Function object, Function.caller, Hierarchy of objects

JavaScript Programmer’s Reference Arguments.caller (Property) (Web hosting packages) The object that

Monday, July 23rd, 2007

JavaScript Programmer’s Reference Arguments.caller (Property) The object that called the function that owns the arguments. Availability: JavaScript 1.1 JScript 5.5 Internet Explorer 5.5 Netscape 3.0 Deprecated Property/method value type: Arguments.object JavaScript syntax: -myArguments.caller This property refers to an Arguments object belonging to a parent function. Function call tracing can traverse a hierarchy based on Arguments objects to unwind a call stack. This might be useful when debugging complex script projects. You can work out the calling tree by tracing the callee and caller relationships back up the execution context tree. The caller is a reference to the arguments object of the caller of the function. To reference the function that called the current one, use this: arguments.caller.callee To get the name of the function that called the current one use this (so long as the interpreter supports the name property on functions): arguments.caller.callee.name With this, you could build a stack trace function that you can call and will unwind the calling context stack to show you how you got to the location you are in. Tools such as this are useful to have around and if they are in a separate .js file, you can include them when you need to debug a script problem. When the caller value is Null, it refers to the global code context because there is no arguments array in that context at least not in a web browser. Other host implementations may provide an additional level of arguments according to how the script is executed. This has no meaning outside of the context of a function. The example shows how to walk up the calling tree and should yield the following output when it is run: level2 called by level1 called by global level

A Arguments.callee (Property) Property JavaScript JScript N

Monday, July 23rd, 2007

A Arguments.callee (Property) Property JavaScript JScript N IE Opera NES ECMA Notes callee 1.2 + 5.5 + 4.0 + 5.5 + - DontEnum caller 1.1 + 5.5 + 3.0 + 5.5 + Warning, DontEnum, Deprecated length 1.1 + 5.5 + 3.0 + 5.5 + - ReadOnly, DontEnum Cross-references: ECMA 262 edition 2 section 10.1.6 ECMA 262 edition 2 section 10.1.8 ECMA 262 edition 2 section 15.2.3.1 ECMA 262 edition 3 section 10.1.6 ECMA 262 edition 3 section 10.1.8 Wrox Instant JavaScript, ISBN 1-861001-27-4 page 27 Arguments.callee (Property) The functionobject being called. Availability: JavaScript 1.2 JScript 5.5 Internet Explorer 5.5 Netscape 4.0 Property/method value type: Function object JavaScript syntax: -myArguments.callee The value yielded by this property is the function object that owns the arguments. You can work out the calling tree by tracing the callee and caller relationships back up the tree. The callee is a reference to the parent function that owns the arguments object. This has no meaning outside of the context of a function. See also: Arguments object, Arguments.caller, Debugging client side, Function object Property attributes: DontEnum.