mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-19 16:11:03 +00:00
Updated JScript Enumerator (markdown)
parent
e988781229
commit
0681bd14ac
|
@ -7,35 +7,41 @@ For example, when accessing the value of an array, it is expressed as `arr(i)` i
|
||||||
### Convert MS/JScript Enumerator to JSObject
|
### Convert MS/JScript Enumerator to JSObject
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// MS JScript Enumerator to Array
|
// The provided code snippet has been corrected by ChatGPT.
|
||||||
if (!Enumerator.prototype.toArray) {
|
// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
|
||||||
Enumerator.prototype.toArray = function() {
|
// Related issues: welsonjs#75 welsonjs#42 welsonjs#30
|
||||||
var a = [];
|
Enumerator.prototype.toArray = function() {
|
||||||
for (; !this.atEnd(); this.moveNext()) {
|
var result = [];
|
||||||
var x = {};
|
while (!this.atEnd()) {
|
||||||
var b = new Enumerator(this.item().Properties_);
|
var currentItem = this.item();
|
||||||
for (; !b.atEnd(); b.moveNext()) {
|
var currentItemProperties = currentItem.Properties_;
|
||||||
var c = b.item();
|
var itemObject = {};
|
||||||
if (typeof c.value !== "unknown") {
|
|
||||||
x[c.name] = c.value;
|
var propertiesEnumerator = new Enumerator(currentItemProperties);
|
||||||
} else {
|
while (!propertiesEnumerator.atEnd()) {
|
||||||
var i = 0, d = [];
|
var property = propertiesEnumerator.item();
|
||||||
while (true) {
|
if (typeof property.value !== "unknown") { // The type "Unknown" is Array
|
||||||
try {
|
itemObject[property.name] = property.value;
|
||||||
d.push(c.value(i));
|
} else {
|
||||||
i++;
|
var arrayValues = [];
|
||||||
} catch (e) {
|
var index = 0;
|
||||||
break;
|
while (true) {
|
||||||
}
|
try {
|
||||||
|
arrayValues.push(property.value(index));
|
||||||
|
index++;
|
||||||
|
} catch (e) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
x[c.name] = d;
|
|
||||||
}
|
}
|
||||||
|
itemObject[property.name] = arrayValues;
|
||||||
}
|
}
|
||||||
a.push(x);
|
propertiesEnumerator.moveNext();
|
||||||
}
|
}
|
||||||
return a;
|
result.push(itemObject);
|
||||||
};
|
this.moveNext();
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### References
|
### References
|
||||||
|
@ -43,4 +49,5 @@ if (!Enumerator.prototype.toArray) {
|
||||||
* https://social.technet.microsoft.com/Forums/systemcenter/en-US/2a0078db-2053-4e21-9262-62ffbc156862/enumerating-fields-returned-with-a-wmi-query?forum=configmgrgeneral
|
* 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
|
* 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/973016/jscript-enumerator-and-list-of-properties
|
||||||
* https://stackoverflow.com/questions/6346766/javascript-enumerator/6346909
|
* https://stackoverflow.com/questions/6346766/javascript-enumerator/6346909
|
||||||
|
* https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
|
Loading…
Reference in New Issue
Block a user