O Object object (Object/core) This will create a new object of the Stringtype. You can invoke the constructor without the new operator but the consequences will depend on the constructor as to what it will yield as a result. In the case of the Stringdata 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 becomes important 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 other object classes inherit its methods and properties. However, in some cases they will get overridden or nulled out. DOM level 2 adds the following properties: contentDocument Although JavaScript is object-based, it does not support true object-oriented classes such as the ones you find in C++, Smalltalk, Java or Objective C. Instead, it provides Constructor mechanisms, which create objects by allocating space for them in memory and assigning initial values to their properties. All functions, including constructors are themselves objects; however, not all objects are 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 the Class properties that you find in true object-oriented languages. Externally, the objects in JavaScript exhibit most of the attributes of a class based object oriented system and some commentators argue that this qualifies JavaScript as being a genuine object oriented system. However I think the following points declassify it as a truly object oriented system, 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-oriented category at which time the prototype inheritance would be replaced with super-class/sub-class mechanisms 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
JavaScript Programmer’s Reference Although these are generally arranged in a tree-like structure, there are many short cut references that mean you can refer to the same object in a variety of ways. For example the Netscape JavaPackageobject can be referred to with the following properties in a Netscape browser: . Netscape . Packages.netscape . window.Packages.netscape Each one refers to an identical object but from the script writer s point of view, some time can be saved by using the short cuts. Scripts also appear simpler to read. However, the downside is that the object model hierarchy becomes confusing unless you know about the short-cuts. These shortcuts provided for ’so-called’ convenience may in fact be exactly the opposite if they are only available on one platform. Using them immediately renders your script non-portable. Object object (Object/core) An object of the class “Object”. 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 -myObject = new Object() JavaScript syntax: -myObject = Object 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 the prototype-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 of which may contain a primitive value, another object, or a function. The constructor is invoked by the newoperator or by calling it as a Constructor function. For example: new String(”Some Text”); 1574
O Object literal (Definition) Object literal (Definition) An object initialiser that creates the object as well. Availability: Property/method value type: ECMAScript edition 3 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 is still “Object”. Object literals can be nested so that the properties of the topmost object can in fact be object literals themselves. The values assigned to the properties as the object is created can be derived by evaluating a JavaScript expression. You can add as many properties as you care to but you must be careful to keep the nesting properly balanced. The result is an object with the properties containing the values described in the literal expression. Example code: // 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 the document, 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 object models interacts with the others and is a way of representing the tangible real-world objects. 1573