JavaScript Tutorial/MS JScript/Enumerator — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:24, 26 мая 2010
Содержание
Enumerator
Syntax
var variable = new Enumerator(collection)
The Enumerator object provides access to items in a collection by allowing iteration through a collection.
Unlike arrays, enumerators can not access a specific position.
Methods Associated with Enumerator Object
Method Description atEnd() Determines if Enumerator is at the end of the collection item() Returns the current item in the collection moveFirst() Resets the Enumerator to the first item in the collection moveNext() Moves Enumerator to the next item in the collection
Enumerator.atEnd()
The atEnd() method returns true if the enumerator is pointing to the last element in the collection; otherwise, it returns false.
True is also returned if the collection is empty or undefined.
<html>
<H1>Drive Letters and drive types:</H1>
<script language="JScript">
<!--
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var en = new Enumerator(fileSysObj.Drives);
for (;!en.atEnd();en.moveNext())
{
document.write("Drive ",en.item().DriveLetter);
document.write(" is of type ",en.item().DriveType,"<br>");
}
-->
</script>
</html>
Enumerator.item()
The item() method returns the element that the enumerator is pointing to in the collection. If the collection is empty or undefined, undefined is returned.
<html>
<h1>Drive Letters and drive types:</h1>
<script language="JScript">
<!--
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var en = new Enumerator(fileSysObj.Drives);
for (;!en.atEnd();en.moveNext())
{
document.write("Drive ",en.item().DriveLetter);
document.write(" is of type ",en.item().DriveType,"<br>");
}
-->
</script>
</html>
Enumerator.moveFirst()
The moveFirst() method moves the enumerator to the beginning of the collection. If the collection is empty or undefined, undefined is returned.
<html>
<H1>Drive Letters and drive types:</H1>
<script language="JScript">
<!--
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var en = new Enumerator(fileSysObj.Drives);
for (;!en.atEnd();en.moveNext()) {
document.write("Drive " + en.item().DriveLetter + " is of type " + en.item().DriveType+"<br>");
}
document.write("<h1>Drive Status:</h1>");
en.moveFirst();
for (;!en.atEnd();en.moveNext()) {
if(en.item().IsReady) {
document.write("Drive ",en.item().DriveLetter);
document.write(" is ready!<br>");
} else {
document.write("Drive ",en.item().DriveLetter);
document.write(" is not ready!<br>");
}
}
-->
</script>
</html>
Enumerator.moveNext()
The moveNext() method moves the enumerator to the next element in the collection. If the collection is empty, undefined is returned.
<html>
<H1>Drive Letters and drive types:</H1>
<script language="JScript">
<!--
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var en = new Enumerator(fileSysObj.Drives);
for (;!en.atEnd();en.moveNext()) {
document.write("Drive ",en.item().DriveLetter);
document.write(" is of type ",en.item().DriveType,"<br>");
}
-->
</script>
</html>