Here is a list of object classes with a note about what sort of object they are and when how theyare managed:Array Native A collection of objects in a sequence Boolean Native A logical v
Trang 1be created and destroyed at a level that is more granular than a function body.
There is also scope for a religious debate on indentation Three space characters works great (forme) I don't like tabs because if you move the source code to another editor, the indentation can goawry Space characters for indentation ensure that the source code looks the same in any
monospaced editing window and probably looks OK in a word processor too
See also: Flow control, if( ) , while( )
Object (Definition)
There is a distinct difference between an object and an Object
We refer to the built-in Object class with a capitalised name When referring generically to objects
of other classes, the word object is all lower case Therefore we can have an Object object and aString object Native objects are built-in, host objects are also built in but created outside of theJavaScript core functionality User-defined objects are not covered here
Trang 2Here is a list of object classes with a note about what sort of object they are and when how theyare managed:
Array Native A collection of objects in a sequence
Boolean Native A logical value container
Date Native A date value container
Function Native A function code container
Global Built-in A container for global properties, methods, and functions
Image Hosted Web browser image wrapper
Math Built-in A container for math functions
Number Native A numeric value
Object Native A generic object
String Native A sequence of characters
Because you might refer to documents in many ways, possibly by means of object properties or as aproperty belonging to another window, it is not safe to assume that the document property
belonging to the Global object the script is attached to is always the document object you aretrying to access Because of this, the object references in the syntax examples assume the object isbeing referred to via a variable called myDocument or myObject etc For example, the value
myDocument is shown being assigned as a variable from the many alternative sources from whichyou can obtain a document object reference
Object (Type)
A native built-in type
Availability: ECMAScript edition – 2
An Object is an unordered collection of properties Each property consists of a name, a value and aset of attributes
See also: Alias, Data Type, Definition, Internal Method, Internal Property, Object object,
Property, Property attribute, Type
Cross-references:
ECMA 262 edition 2 – section 8.6
ECMA 262 edition 3 – section 8.6
Wrox Instant JavaScript – page 28
Trang 3O – Object constant (Definition)
Object constant (Definition)
See also: Array(), Boolean(), Closure(), Constant expression, Date(),
Function(), Global object, Math object, Number(), Objectliteral, Object()
Cross-references:
Wrox Instant JavaScript – page 28
Object inspector (Useful tip)
A debugging tool for inspecting object properties and classes
Here is a small debugging utility that breaks an object down and displays some of its properties
Trang 5O – Object literal (Definition)
Object literal (Definition)
An object initialiser that creates the object as well
Property/method value type: Object object
JavaScript version 1.2 introduces Object literals
The object is created and returned by the expression This would normally be assigned to a
variable, which effectively names the object It isn't the object class but it can be copied Its class isstill "Object"
Object literals can be nested so that the properties of the topmost object can in fact be object
// Create a simple object literal
var simple = { prop:100 };
// Create a nested object literal
var nested = { reference: { prop:100 } };
// Create a nested object literal with expression derived value
var evaluated = { reference: { prop:(Math.random()*100) } };
See also: Object constant, Object.constructor
Cross-references:
ECMA 262 edition 3 – section – 11.1.5
O'Reilly JavaScript Definitive Guide – page – 45
Object model (Definition)
There are several different object models that are realized in JavaScript implementations
In the Netscape and MSIE web browsers, the object models are provided as representations of thedocument, the browser, event capturing mechanisms, and the style sheet In addition, some
implementations model the environs, the operating system, and the file system Each of these objectmodels interacts with the others and is a way of representing the tangible real-world objects
Trang 6Although these are generally arranged in a tree-like structure, there are many short cut referencesthat mean you can refer to the same object in a variety of ways For example the Netscape
JavaPackage object can be referred to with the following properties in a Netscape browser:
Object object (Object/core)
An object of the class "Object"
Availability: ECMAScript edition – 2
JavaScript – 1.1JScript – 3.0Internet Explorer – 4.0Netscape – 3.0Netscape Enterprise Server 2.0Opera 3.0
JavaScript syntax:
Object properties: parent , proto , constructor, name, prototype
Object methods: assign(), eval(), hasOwnProperty(), isPrototypeOf(),propertyIsEnumerable(), toLocaleString(),
toSource(), toString(), unwatch(), valueOf(),watch()
An instance of the class "Object" is created by using the new operator on the Object()
constructor The new object adopts the behavior of the built-in prototype object through theprototype-inheritance mechanisms
All properties and methods of the prototype are available as if they were part of the instance
An Object is a member of the type Object It is an unordered collection of properties, each ofwhich may contain a primitive value, another object, or a function
The constructor is invoked by the new operator or by calling it as a Constructor function For example:
new String("Some Text");
Trang 7O – Object object (Object/core)
This will create a new object of the String type You can invoke the constructor without the newoperator but the consequences will depend on the constructor as to what it will yield as a result Inthe case of the String data type, the constructor could be invoked like this:
String("Some Text");
However, you would get a primitive string as a result from this and not a String object JavaScript
is somewhat forgiving and you may not notice this happening until later on when it becomesimportant that you have a String object and not a simple string
Because this object is the topmost parent object in the prototype inheritance hierarchy, all otherobject classes inherit its methods and properties However, in some cases they will get overridden
constructors Each constructor has a Prototype property that is used to facilitate inheritance based
on the prototype It also provides for shared properties, which is similar to but not the same as theClass properties that you find in true object-oriented languages
Externally, the objects in JavaScript exhibit most of the attributes of a class based object orientedsystem and some commentators argue that this qualifies JavaScript as being a genuine objectoriented system However I think the following points declassify it as a truly object orientedsystem, meaning that it is an "object like" system:
❑ Global variables and the scope chain mechanism
❑ Prototype based inheritance
❑ Creation of multiple objects and calling them within a single script
❑ Object data is not truly private
It’s a close enough call that JavaScript 2.0 may well move it into the class-based object-orientedcategory at which time the prototype inheritance would be replaced with super-class/sub-classmechanisms and the arguments become null and void
Warnings:
❑ Be very careful not to confuse this generic top-level core object with the object that MSIE instantiates
to represent an <OBJECT> tag MSIE creates OBJECT objects for that purpose but also supportsObject objects For this reason, it may be the case that interpreters cannot become case-insensitivewhen matching class names If they did, then it would be impossible to distinguish between Objectand OBJECT class names
Trang 8See also: Aggregate type, Array object, Boolean object, Date object, delete, Function
object, Math object, Native object, Number object, Object, OBJECT object,Object(), Object(), Object.Class, Object.prototype, String object,userDefined object
Deprecatedeval() 1.1 + 3.0 + 3.0 + 4.0 + 3.0 + 2.0 + - Warning,
DeprecatedhasOwn
unwatch() 1.2 + - 4.0 + - - 3.0 + - WarningvalueOf() 1.1 + 3.0 + 3.0 + 4.0 + 3.0 + 2.0 + 2 + -
Cross-references:
ECMA 262 edition 2 – section 4.2.1
ECMA 262 edition 2 – section 4.3.3
ECMA 262 edition 2 – section 10.1.5
ECMA 262 edition 2 – section 15.2
ECMA 262 edition 3 – section 4.2.1
ECMA 262 edition 3 – section 4.3.3
Trang 9O – Object() (Constructor)
ECMA 262 edition 3 – section 10.1.5
ECMA 262 edition 3 – section 15.2
O'Reilly JavaScript Definitive Guide – page 44
Wrox Instant JavaScript – page 28
Object() (Constructor)
An Object object constructor
Availability: ECMAScript edition – 2
JavaScript – 1.1JScript – 3.0Internet Explorer – 4.0Netscape – 3.0Netscape Enterprise Server 2.0Opera 3.0
Property/method value type: Object object
JavaScript syntax:
When Object is called as part of a new expression, it is a constructor that may create an object instance.There are limitations what is sensible for the new operator to be able to do with the Object
constructor Since the Object is considered to be the highest ancestor of all objects in the prototypeinheritance chain, you cannot logically have more than one Object object Passing other nativeobjects to the Object Constructor implies a type casting from their native object type to theObject type That's not logical either The main use of the Object Constructor then is to
manufacturer object instantiations from non-object data types
The table summarizes the resulting values from using the Object() constructor with the new operator
No argument Creates a new empty object
null Creates a new empty object
undefined Creates a new empty object
Boolean Create a new boolean object whose default value is the input valueNumber Create a new number object whose default value is the input valueString Create a new string object whose default value is the input valueNative object Return the native object itself
Host object Host implementation dependant behavior Objects are cloned if
necessary but some may not be
Trang 10Unless you assign the result of the new operation, an object will simply consume memory Youneed to store a reference to it at the time it is instantiated You can do this by assigning it to avariable or a property of another object, passing it in to a function and making sure it gets retained
in there, or storing it as an element in an array
Warnings:
❑ You can refer to objects without the parentheses but then you are not referring to a constructorfunction but to the object itself The behavior varies between browsers and depends on the kind ofobject being instantiated and probably depends on whether it is a wrapper for a primitive data type
or a more complex aggregated type
❑ These all appear to create the same kind of object in both MSIE and Netscape
myObject = Object();
myNewObject = new Object();
myOtherObject = new Object;
These do not:
myBoolean = Boolean();
myNewBoolean = new Boolean();
myOtherBoolean = new Boolean;
❑ In the case of the Boolean, Number, and String object types, only the first form will initialize the newobject with a value Placing the result of these examples in document.write() statements
illustrates the behavior You may want to examine the objects returned in more detail by developing
an object inspector script
See also: Boolean(), Constructor function, constructor property, Garbage collection, Global
object, Memory leak, new, Number(), Object constant, Object object,Object.prototype, Reference counting, String()
Cross-references:
ECMA 262 edition 2 – section 15.1.1
ECMA 262 edition 2 – section 15.1.3.1
ECMA 262 edition 2 – section 15.2.2.2
ECMA 262 edition 3 – section 15.2.2
Trang 11O – Object() (Function)
Object() (Function)
An Object object constructor
JavaScript – 1.1JScript – 1.0Internet Explorer – 3.02Netscape – 3.0
Property/method value type: An object of a type that depends on the passed in argument
JavaScript syntax:
Argument list: aValue A value to be stored in the new object
The Object Constructor can be called as a function When this happens, the value passed in
undergoes a type conversion
In an ECMA-compliant implementation, the Object constructor function uses the ToObjectconversion However it handles input values undefined and null as special cases and creates anew object as if the constructor had been used with the new operator
The table summarizes the results based on the input value data types
See also: Cast operator, Constructor function, constructor property, Implicit
conversion, Object object
Cross-references:
ECMA 262 edition 2 – section 15.1.1
ECMA 262 edition 2 – section 15.1.3.1
ECMA 262 edition 2 – section 15.2.2.2
ECMA 262 edition 3 – section 15.2
Trang 12Object. parent (Property)
A special property in which to access the scope chain during function execution
Netscape – 4.0
Property/method value type: ScopeChain object
Object. proto (Property)
A special property in which to access the prototype inheritance chain during construction
Netscape – 4.0
Property/method value type: Function object
See also: Lexical scoping, Prototype Based Inheritance, Prototype chain,
Warnings:
❑ This method is deprecated in favor of the Object.watch() and Object.unwatch() methods
Trang 13O – Object.Class (Property/internal)
Object.Class (Property/internal)
Internal property that returns an object class
This is an internal property that describes the class that an Object object instance is a member of.The reserved words suggest that in the future, this property may be externalized
Property attributes:
DontEnum, Internal
Cross-references:
ECMA 262 edition 2 – section – 8.6.2
ECMA 262 edition 2 – section – 15.2.2.1
ECMA 262 edition 3 – section – 8.6.2
Object.constructor (Property)
A reference to a constructor object
JavaScript – 1.1JScript – 1.0Internet Explorer – 3.02Netscape – 3.0
Opera browser – 3.0
Property/method value type: Object object
The initial value of the Object.prototype.constructor is the built-in Object constructor.You can use this as one way of creating objects although it is more popular to use the new
Object() technique
This property is useful if you have an object that you want to clone but you don't know what sort
of object it is Simply access the constructor belonging to the object you have a reference to
Netscape provides constructors for many objects, virtually all of them in fact, even when it ishighly inappropriate to do so MSIE is far more selective and there are some occasions when youmight wish for a constructor that MSIE does not make available
Trang 14ECMA 262 edition 2 – section – 15.2.4.1
ECMA 262 edition 3 – section – 15.2.2
Object.eval() (Method)
Evaluate the JavaScript source text passed in a string argument
JScript – 3.0Internet Explorer – 4.0Netscape – 3.0Netscape Enterprise Server version – 2.0Opera browser – 3.0
Deprecated
Property/method value type: Function result
A method that can be used to test whether a property exists and belongs to the receiving object
JavaScript – 1.5JScript – 5.5Internet Explorer – 5.5Netscape – 6.0
Property/method value type: Boolean primitive
For this method to yield a Boolean true value, the property named in the argument must exist andmust belong to the receiving object If the property is inherited from a prototype or earlier ancestorthen this method returns false
Trang 15O – Object.isPrototypeOf() (Method)
This method would be useful if it could test for the existence of a property in the inheritance chain.There is an internal HasProperty() method but the ECMA standard indicate that it is not
exposed to the script interface
Cross-references:
ECMA 262 edition 3 – section – 15.2.4.5
Object.isPrototypeOf() (Method)
A test for the relationship between two objects to ascertain direct parentage
JavaScript – 1.5JScript – 5.5Internet Explorer – 5.5Netscape – 6.0
Property/method value type: Boolean primitive
Argument list: anObject The object whose prototype is to be tested
The receiving object is tested for identity against the object referred to by the prototype property ofthe object passed as an argument If the object in the argument is a direct child object through theprototype chain, then this method returns a true value
Property/method value type: String primitive
Trang 16Objects are identified either by the NAME="… " HTML tag attribute or by the ID="… " HTMLtag attribute.
Netscape shows a marginal preference for the name property while MSIE seems slightly betterdisposed towards the ID property However in many cases, both browsers support either techniqueand in some cases will locate items named with either tag as if they existed in a single namespace
Object.propertyIsEnumerable() (Method)
A test for whether a property has the don't enumerate flag set or not
JavaScript – 1.5JScript – 5.5Internet Explorer – 5.5Netscape – 6.0
Property/method value type: Boolean primitive
Argument list: aName The name of the object property to test
If the receiving object has a member property of the name that is passed in the argument, and if theDontEnum attribute of that property is false, then this method returns the Boolean true value
Cross-references:
ECMA 262 edition 3 – section 15.2.4.7
Object.prototype (Property)
The prototype for the Object object, which can be used to extend the interface for all Object objects
JavaScript – 1.1JScript – 3.0Internet Explorer – 4.0Netscape – 3.0Opera browser – 3.0
Property/method value type: Object object
Trang 17The prototype property for the Object prototype object is null.
The example demonstrates how to provide extensions to all instances of this class by adding afunction to the prototype object
// Create a new object
myObject = new Object();
See also: Arguments object, Function.arguments[], JellyScript, Object
object, Object(), Object.constructor, Object.toString(),Object.valueOf(), prototype property
Trang 18Property attributes:
ReadOnly, DontDelete, DontEnum
Cross-references:
ECMA 262 edition 2 – section 15.2.3.1
ECMA 262 edition 2 – section 15.2.4
ECMA 262 edition 3 – section 15.2.3.1
Property/method value type: String primitive
The locale context supplies some special conversion rules for strings Depending on the locale, thismight include special characters or a means of using double byte characters It may also affect thedirection of the text, for certain Asian locales for example
Property/method value type: String primitive
Trang 19O – Object.toString() (Method)
This is an alternative way to deliver a string version of an object's internal values In this case, it isformatted as an Object literal and can then be used in an eval() function to assign another object.The exact format of what you see depends on the object being examined
The result of calling this method is string version of the object formatted as an Object literal
Warnings:
❑ Note that this is not available in the MSIE browser but can be useful when constructing an Objectinspector for use in Netscape
Object.toString() (Method)
Return a string primitive version of an object
JavaScript – 1.1JScript – 3.0Internet Explorer – 4.0Netscape – 3.0Opera browser – 3.0
Property/method value type: String primitive
When the toString() method of an Object.prototype is invoked, the class name of the object
ECMA 262 edition 2 – section – 15.2.4.2
ECMA 262 edition 3 – section – 15.2.4.2
Trang 20Object.unwatch() (Method)
A method to disable a watch that was set up on a property change
Availability: JavaScript – 1.2
Netscape – 4.0Netscape Enterprise Server – 3.0
This is inherited by most object classes in Netscape
The primitive numeric value of the object
Availability: ECMAScript edition – 2
JavaScript – 1.1JScript – 3.0Internet Explorer – 4.0Netscape – 3.0Netscape Enterprise Server – 2.0Opera – 3.0
Property/method value type: Depends on the object value
Trang 21O – Object.watch() (Method)
As a general rule, the valueOf() method for an object simply returns the this property of theobject itself However, the object may be a wrapper for a host object some kind It may thereforehave been created by invoking the Object constructor In that case, the host object should be
returned in an ECMA-compliant implementation
Implementations may choose to return the this property of an object or some other value if they choose.The result of this method will be implementation-and object-dependant The native core objects arewell defined and will return predictable value types Generally these will be defined by ECMA orW3C standards It is up to the hosting environment to provide the valueOf() interface to its ownsuite of objects
See also: Cast operator, Object.prototype, valueOf()
Cross-references:
ECMA 262 edition 2 – section – 15.2.2.1
ECMA 262 edition 2 – section – 15.2.4.3
ECMA 262 edition 3 – section – 15.2.4.4
Object.watch() (Method)
A means of establishing a call back when a property value changes
Availability: JavaScript – 1.2
Netscape – 4.0Netscape Enterprise Server version – 3.0
This is inherited by most object classes in Netscape
Trang 22Object property delimiter (.) (Delimiter)
A token to delimit object properties from their object
Availability: ECMAScript edition – 2
JavaScript – 1.0JScript – 1.0Internet Explorer – 3.0Netscape – 2.0Netscape Enterprise Server version – 2.0Opera browser – 3.0
JavaScript syntax:
- myObject.aProperty.aProperty
Argument list: aProperty The identifier name of property to be accessed
The dot delimits properties and objects It can find properties of properties of objects too
The associativity is left to right
Refer to the Operator Precedence topic for details of execution order
You can also access the property values as if the object were an array This:
ECMA 262 edition 2 – section 8.6
ECMA 262 edition 2 – section 11.2
ECMA 262 edition 3 – section 8.6
ECMA 262 edition 3 – section 11.2.1
Wrox Instant JavaScript – page 28
Trang 23O – OBJECT object (Object/HTML)
OBJECT object (Object/HTML)
This is an object that encapsulates an ActiveX plugin Do not confuse it with the Object object that
is the super-class of all objects in JavaScript
Availability: DOM level – 1
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Inherits from: Element object
HTML syntax: <OBJECT> </OBJECT>
anIndex A reference to an element in a collection
aName An associative array reference
Argument list:
anElementID The ID value of an Element object
Object properties: accessKey, align, altHtml, archive, border, classid,code, codeBase, codeType, data, dataFld, dataSrc,
declare, form, height, hspace, name, object, readyState,standby, tabIndex, type, useMap, vspace, width
Event handlers: onAfterUpdate, onBeforeUpdate, onBlur, onClick,
onDataAvailable, onDataSetChanged, onDataSetComplete,onDblClick, onDragStart, onError, onErrorUpdate,onFilterChange, onFocus, onHelp, onKeyDown, onKeyPress,onKeyUp, onMouseDown, onMouseMove, onMouseOut,
onMouseOver, onMouseUp, onReadyStateChange, onRowEnter,onRowExit, onSelectStart
This is an object representing an <OBJECT> HTML tag
The <OBJECT> tag is a block-level tag That means that it forces a line break before and after itself.This object is specific to the MSIE browser when it runs on the Windows operating system Noother browser supports ActiveX as well as MSIE and no other operating system properly or
completely supports the ActiveX infrastructure
The events handled, and the properties and the methods of this object will depend on the kind ofActiveX object that is created
The DOM level 1 specification refers to this as an ObjectElement object
Trang 25-O – -OBJECT object (-Object/HTML)
-onBlur 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - - WarningonClick 1.5+ 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + Warning
Trang 26OBJECT.align (Property)
An alignment control for an <OBJECT> tag's position with respect to its parent object
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
The alignment of the ActiveX OBJECT object with respect to its containing parent object is defined
in this property The expected and widely available set of alignment specifiers are available:
Property/method value type: String primitive
The alternative HTML is used in case the base <OBJECT> tag experiences a problem when loading
or the browser cannot use ActiveX objects as embeds Of course if this property is accessible fromthe OBJECT object during scripting, the browser must have parsed the <OBJECT> tag, although itmay still have had problems with the component
This HTML is enclosed between the <OBJECT> and </OBJECT> tags in the HTML document source
Trang 27O – OBJECT.archive (Property)
Certain tags are likely to be omitted from the altHTML property value <OBJECT> blocks contain
<PARAMETER> tags for passing values to the embedded ActiveX component Clearly you won'twant these appearing in the display if the component fails to load The <PARAMETER> tags areconsidered integral to the <OBJECT> and it’s smart enough to disregard them as it constructs itsalternative HTML block
Browsers that cannot understand and render <OBJECT> tags should also ignore the <PARAMETER>tags too
Property/method value type: String primitive
This is a new attribute of the DOM HTMLObjectElement but is shown here as this is the existingobject type it is to be added to
OBJECT.border (Property)
The width of the border around the object when it is rendered into the display
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
This property can be set from script and although its type is a String primitive, it will expect anumeric value JavaScript will coerce as necessary during the assignment
Trang 28OBJECT.classid (Property)
The URL that locates the registered ActiveX control within the local file system when MSIE is used
on the Windows platform
Internet Explorer – 4.0
Property/method value type: String primitive
This is a special URL value used to locate ActiveX objects within the file system of the PC runningthe client browser This is likely only available in Windows versions of the MSIE browser becausethat is the only platform that supports ActiveX objects It is not supported on the Macintosh version
of MSIE because ActiveX objects aren't available there This is because they are compiled x86 code and therefore cannot run in a non-Intel environment (unless the x86 CPU is being emulated).The ActiveX control needs to have been registered and installed already It is possible to construct
micro-an <OBJECT> tag that conveys sufficient information to locate and install a missing ActiveX controlbut this can be a quite involved process
Property attributes:
ReadOnly
OBJECT.code (Property)
The name of a Java applet to be used with the <OBJECT> tag
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
This specifies the main code class to be loaded when the object is instantiated This value is added
to the codebase property to form a fully qualified URL
There is conflicting information in the reference sources regarding the read/write ability of thisproperty Some suggest it is ReadOnly and others suggest you can assign a value to it It may bethat you can assign a value to it without the JavaScript interpreter complaining but that any valueyou assign is ignored
Trang 29Property/method value type: String primitive
The codebase is the path to the directory where the classes specified in the code property arelocated The actual path to the required files is generated by a string concatenation of
codebase+code to generate a fully specified URL
Due to security limitations it is not permitted to access a codebase value that is outside the domainspecified by the containing document
There is conflicting information in the reference sources regarding the read/write ability of thisproperty Some suggest it is ReadOnly and others suggest you can assign a value to it It may bethat you can assign a value to it without the JavaScript interpreter complaining but that any valueyou assign is ignored
OBJECT.codeType (Property)
A description of the type of code in the object referred to by the CLASSID="… " HTML tag attribute
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
This is a MIME type value that describes the kind of code being embedded by the <OBJECT> tag.There is conflicting information in the reference sources regarding the read/write ability of thisproperty Some suggest it is ReadOnly and other suggest you can assign a value to it It may bethat you can assign a value to it without the JavaScript interpreter complaining but that any valueyou assign is ignored
Trang 30OBJECT.data (Property)
A URL that points at a file containing data that the OBJECT element can access
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
This is intended for passing in a URL that the ActiveX object can use to access some data servicethat is online and available for access via the network It is not the URL of the ActiveX object itself
Property attributes:
ReadOnly
OBJECT.declare (Property)
A means of defining the object without activating it
JavaScript – 1.5Netscape – 6.0
Property/method value type: Boolean primitive
Declaring an OBJECT in this way may be useful when referring to the object from elsewhere in thepage or from within another object Sometimes you simply want to know something about it,perhaps one of its parameters For video players, sometimes its useful to instantiate the OBJECTinto the display without playing the video right away
OBJECT.form (Property)
The form that an object belongs to if it is used for form input
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: Form object
Trang 31O – OBJECT.height (Property)
Property attributes:
ReadOnly
OBJECT.height (Property)
The height of an area reserved for displaying the contents of the <OBJECT> tag
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: Number primitive
The object space is defined by an extent rectangle that surrounds the space occupied by it on thescreen An extent rectangle is the smallest rectangle that completely encloses the item This
property specifies the height of that extent rectangle
OBJECT.hspace (Property)
A horizontal margin space either side of the <OBJECT> tag with respect to its surrounding objects
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: Number primitive
Margins placed around objects are either modified separately with all four margin sides having adifferent property or by adjusting the horizontal margins and vertical margins using just two values.The hspace property controls the margin to the left and right of the object
Trang 32OBJECT.name (Property)
The value of the NAME="… " HTML tag attribute
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
Objects are identified either by the NAME="… " HTML tag attribute or by the ID="… "
HTML tag attribute
Netscape shows a marginal preference for the name property while MSIE seems slightly betterdisposed towards the ID property However in many cases, both browsers support either techniqueand in some cases will locate items named with either tag as if they existed in a single namespace
See also: NAME="… ", Namespace
Property/method value type: Object object
If a property is a public property of the ActiveX object, and that name coincides with a property ofthe JavaScript object that is instantiated by the <OBJECT> HTML tag, then access to the propertybelonging to the containing object is difficult This is because the search order will see the publicproperty of the ActiveX object first By using the object property, once can access the containingobject explicitly and retrieve a property of that object even if there is an identically named propertybelonging to the enclosed ActiveX object
This access mechanism applies to method invocations as well
Property attributes:
ReadOnly
Trang 33Property/method value type: String primitive
This property reflects the loading status of an <OBJECT> tag and its corresponding OBJECT objectinstantiation
Sometimes, you can design scripts to execute while the document is downloading Inline scripts forexample At that time, you may even be able to trigger interval timed deferred executions as well
If it is important that the document has completed loading, you can check this property for one ofthe following values:
uninitialized The object is first instantiated but has not begun loading
loading The object has commenced loading
loaded The object has completed loading
interactive The object is loaded but not yet closed but is ready to handle
interaction
complete The object body has been closed and the loading is finished
An object may not need to reflect the complete status before you can commence operating on it Otherobjects may require that they are completely loaded For example, you cannot create an OBJECTobject that represents an <OBJECT> tag until the <BODY> has completed loading This is because theActiveX object construction requires a complete document body structure to attach itself to
Every time this readyState value changes, it triggers an onReadyStateChange event call-back
Property attributes:
ReadOnly
Trang 34OBJECT.standby (Property)
Sets or resets the message text displayed while the object is loading
JavaScript – 1.5Netscape – 6.0
Property/method value type: String primitive
OBJECT.tabIndex (Property)
A control of where the OBJECT object appears in the tabbing order of the page
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: Number primitive
This value indicates where in the tabbing sequence this object and any of its children will beplaced The tabbing order is used when filling in forms or moving focus Pressing the [tab] keymoves from one form element to the next according to the cascaded tabbing order defined bybuilding a tree-like structure with the tab index values
OBJECT.type (Property)
An indication of the MIME type of the object if its codeType property is undefined
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
The MIME type of the object is accessible through the value of this property
Refer to the MIME type topic for details of the available MIME types you will likely see in this property
Trang 35O – OBJECT.useMap (Property)
OBJECT.useMap (Property)
The URL of a <MAP> defined hash element that defines a client-side image map
JavaScript – 1.5Netscape – 6.0
Property/method value type: String primitive
This property reflects the value of the USEMAP="… " HTML tag attribute, which should refer to thenamed <MAP> tag containing an image map The reference is by means of a "#NAME" value in thisproperty that corresponds to the NAME="… " HTML tag attribute of the <MAP> tag describing theimage map to use with the object
OBJECT.vspace (Property)
A vertical spacing above and below the <OBJECT> with respect to its adjacent objects
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
Margins placed around objects are either modified separately with all four margin sides having adifferent property or by adjusting the horizontal margins and vertical margins using just two values.The vspace property controls the margin at the top and bottom of the object
OBJECT.width (Property)
The height of an area reserved for displaying the contents of the <OBJECT> tag
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: String primitive
Trang 36The object space is defined by an extent rectangle that surrounds the space occupied by it on thescreen An extent rectangle is the smallest rectangle that completely encloses the item This
property specifies the width of that extent rectangle
Obsolescent (Definition)
A feature of the language that is no longer supported
Warnings:
❑ If you use obsolescent functionality, your script may fail when it is deployed on other platforms
Octal value (Definition)
A numeric value based on a radix of 8
An octal value is an integer composed of only the following characters:
0 1 2 3 4 5 6 7
Octal values are always prefixed by a zero character
The sequence carries over for the next increment when each column reaches the value 7 Thus:
00 01 02 03 04 05 06 07 010 011 012
Octal values have a historical significance from having been used in the earliest computer systems.However these days, they are particularly useful since they map quite conveniently to the binarysystem Each octal digit corresponds to three binary digits
The most significant of the three octal digits does not have a full range since it contains a carry overbit and a three digit octal number actually represents a 9 bit value However, an 8 bit value can beencoded conveniently if the range is limited to 0377 as a maximum Hexadecimal values map farmore conveniently although they are harder to compute mentally
Trang 37O – Off by one errors (Pitfall)
Warnings:
❑ Beware when you prefix decimal values with a zero character You may want to justify a column offigures If you add leading zero characters to a numeric string, if that string is subsequently parsedback to a numeric value, you may inadvertently export the value as a decimal but import it as anoctal value This can lead to an extremely difficult-to-diagnose fault in your software because theparsers sometimes add some intelligence and will correctly interpret the value as decimal if thecharacters 8 or 9 are present, but otherwise interpret it as octal notation
❑ This may be implementation-dependant behavior to some extent
❑ Be careful that you remove any leading zero characters from the text strings that you plan to convertusing the numeric parser The example shows a simple function for doing this
ECMA 262 edition 3 – section – B.1
O'Reilly JavaScript Definitive Guide – page – 35
Off by one errors (Pitfall)
An error caused by missing the target value by one
This kind of errors are caused by the following:
❑ Forgetting than an index is zero-based and assuming it begins at 1 This typically affects arraysand strings
❑ Enumerating through a range of values and testing for equality with the target value rather thantesting that you are still less than the target value This is typically a problem when you build forloops
See also: Array index delimiter ([ ]), Array.slice(), do while( ), for(
) , Pitfalls, while( )
Trang 38Off-screen image caching (Useful tip)
A technique for caching images locally in readiness for an animation
Property/method value type: Boolean or String primitive
An object that represents the ordered list contained in an <OL> tag
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Trang 39O – OL object (Object/HTML)
HTML syntax: <OL> … </OL>
anIndex A reference to an element in a collection
aName An associative array reference
Argument list:
anElementID The ID value of an Element object
Object properties: compact, start, type
Event handlers: onClick, onDblClick, onDragStart, onFilterChange,onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown,
onMouseMove, onMouseOut, onMouseOver, onMouseUp,onSelectStart
The <OL> tag is a block-level tag That means that it forces a line break before and after itself.The DOM level 1 standard describes this as a HTMLOListElement object
See also: Element object, UL object
onKeyDown 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + WarningonKeyPress 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + WarningonKeyUp 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + WarningonMouseDown 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + WarningonMouseMove 1.5 + 3.0 + 6.0 + 4.0 + - - 4.0 + WarningonMouseOut 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + WarningonMouseOver 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + WarningonMouseUp 1.5 + 3.0 + 6.0 + 4.0 + 3.0 + - 4.0 + Warning
-Inheritance chain:
Element object, Node object
Trang 40OL.compact (Property)
A switching attribute that condenses the space required to display the ordered list on the screen
JavaScript – 1.5JScript – 3.0Internet Explorer – 4.0Netscape – 6.0
Property/method value type: Boolean primitive
The collection of LI objects are presented in the normal spaced out style when the compact
property belonging to their owner OL object is set to false
Setting the property to true should result in the list items being squeezed closer together howeverthe functionality is rarely supported on web browsers
Its more likely that you'll apply CSS style attributes to the list to achieve the same effect
Property/method value type: Number primitive
Ordered lists can start at any value This is somewhat related to the LI.value property, whichallows the list items to begin sequencing from any value you care to define The value you specifyhere must be a positive integer