mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
7
JScript Enumerator
Namhyeon, Go edited this page 2023-11-24 14:34:23 +09:00
Table of Contents
JScript Enumerator
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.
Convert MS/JScript Enumerator to JSObject
// 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;
};
References
- 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
Outdated content warning
This document may contain outdated content. For the latest information, please contact us directly or refer to the webpage below.