-
-
Notifications
You must be signed in to change notification settings - Fork 16
JScript Enumerator
Namhyeon, Go edited this page Nov 24, 2023
·
7 revisions
JScript has a class called Enumerator. This shows a small difference from the standard JavaScript.
For example, when accessing the value of an array, it is expressed as arr(i)
instead of arr[i]
. In this case, the type of array in JScript is marked as unknown
, so in some cases, it has to be converted appropriately.
// The provided code snippet has been corrected by ChatGPT.
// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
// Related issues: welsonjs#75 welsonjs#42 welsonjs#30
Enumerator.prototype.toArray = function() {
var result = [];
while (!this.atEnd()) {
var currentItem = this.item();
var currentItemProperties = currentItem.Properties_;
var itemObject = {};
var propertiesEnumerator = new Enumerator(currentItemProperties);
while (!propertiesEnumerator.atEnd()) {
var property = propertiesEnumerator.item();
if (typeof property.value !== "unknown") { // The type "Unknown" is Array
itemObject[property.name] = property.value;
} else {
var arrayValues = [];
var index = 0;
while (true) {
try {
arrayValues.push(property.value(index));
index++;
} catch (e) {
break;
}
}
itemObject[property.name] = arrayValues;
}
propertiesEnumerator.moveNext();
}
result.push(itemObject);
this.moveNext();
}
return result;
};
- https://stackoverflow.com/questions/23513680/why-does-swbemservices-execquery-return-more-properties-than-requested
- https://social.technet.microsoft.com/Forums/systemcenter/en-US/2a0078db-2053-4e21-9262-62ffbc156862/enumerating-fields-returned-with-a-wmi-query?forum=configmgrgeneral
- http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/Enumeratoritem.htm
- https://stackoverflow.com/questions/973016/jscript-enumerator-and-list-of-properties
- https://stackoverflow.com/questions/6346766/javascript-enumerator/6346909
- https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
This document may contain outdated content. For the latest information, please contact us directly or refer to the webpage below.