please dont rip this site
Microsoft® JScript
Objects
| Tutorial |


What Are Objects?

In Microsoft JScript, objects are, essentially, collections of properties and methods; A method is a function that is a member of an object, and a property is a value or set of values (in the form of an array or object) that is a member of an object. For example, SQRT2 (a number, an approximation of the square root of 2) is a property of the Math object, and substring() (a function) is a method of the string object.

Objects as Arrays

In JScript, objects and arrays are handled identically. You can refer to any of the constituents of an object (its properties and methods) either by name (using the name of the object, followed by a period, followed by the name of the property) or by its array subscript index. Subscript numbering in JScript begins with 0. For convenience, the subscript can also be referred to by its name.

Thus, a property can be referred to in several ways. All of the following statements are equivalent.


theWidth = spaghetti.width;
theWidth = spaghetti[3];  //  [3] is the "width" index.
theWidth = spaghetti["width"];
While it is possible to use brackets to refer to a property by its numeric index, it is not possible to use the "." convention with index numbers. The following statement generates an error.


theWidth = spaghetti.3;
When an object has another object as a property, the naming convention extends in a straightforward way.


var init4 = toDoToday.shoppingList[3].substring(0,1);  //  shoppingList, an array, is a property of toDoToday.
The fact that objects can have other objects as properties lets you generate arrays with more than one subscript, which are not directly supported. The following code creates a multiplication table for values from 0 times 0 through 16 times 16.


var multTable = new Array(17);  //  Make the shell that will become the table.
for (var j = 0; j < multTable.length; j++)  {  //  Prepare to fill it with rows.
    var aRow = new Array(17);  //  Create a row.
    for (var i = 0; i < aRow.length; i++)  {  //  Prepare to fill the row.
    aRow[i] = (i + " times " + j + " = " + i*j);  //  Make and place one value.
    }
multTable[j] = aRow;  //  Put the filled row into the table.
}
To refer to one of the elements of an array of this kind, use multiple sets of brackets.

var multiply3x7 = multTable[3][7];
The following statement generates an error.

var multiply3x7 = multTable[3, 7];

© 1996 by Microsoft Corporation.


file: /Techref/language/asp/js/310.htm, 3KB, , updated: 1996/11/22 10:12, local time: 2024/11/27 22:50,
TOP NEW HELP FIND: 
18.227.0.57:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/TECHREF/language/asp/js/310.htm"> Microsoft&#174; JScript Language Tutorial </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .