From 64d3fcc7efef507b752e74af63a0b00acb8d183a Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 9 Aug 2025 09:25:02 +0900 Subject: [PATCH] Updated JScript Enumerator (markdown) --- JScript-Enumerator.md | 45 +++---------------------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/JScript-Enumerator.md b/JScript-Enumerator.md index 3bf1583..9a66241 100644 --- a/JScript-Enumerator.md +++ b/JScript-Enumerator.md @@ -2,47 +2,7 @@ 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 - -```js -// 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; -}; -``` +Starting from WelsonJS version **0.2.7.54**, the `Array.from()` method is supported for `Enumerator` objects. ### References * https://stackoverflow.com/questions/23513680/why-does-swbemservices-execquery-return-more-properties-than-requested @@ -50,4 +10,5 @@ Enumerator.prototype.toArray = function() { * 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 \ No newline at end of file + * https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa + * https://github.com/joncasey/modern-hta \ No newline at end of file