Using nsISimpleEnumerator

  • Revision slug: Using_nsISimpleEnumerator
  • Revision title: Using nsISimpleEnumerator
  • Revision id: 66570
  • Created:
  • Creator: mcpherrinm
  • Is current revision? Yes
  • Comment Broken link; one or more formatting changes

Revision Content

Using nsISimpleEnumerator

  • <stringbundle>.strings
var enumerator = document.getElementById('aStringBundleID').strings;
var s = "";
while (enumerator.hasMoreElements()) {
  var property = enumerator.getNext().QueryInterface(Components.interfaces.nsIProperty);
  s += property.name + ' = ' + property.value + ';\n';
}
alert(s);

Example using JavaScript 1.7 features

// creates a generator iterating over enum's values
function generatorFromSimpleEnumerator(enum, interface) {
  while (enum.hasMoreElements()) {
    yield enum.getNext().QueryInterface(interface);
  }
}
var b = document.getElementById("stringbundleset").firstChild
var props = generatorFromEnumerator(b.strings, Components.interfaces.nsIPropertyElement);
var s = "";
for (let property in props) {
  s += property.key + ' = ' + property.value + ';\n';
}
alert(s);

Revision Source

<h3 id="Using_nsISimpleEnumerator" name="Using_nsISimpleEnumerator">Using nsISimpleEnumerator</h3>
<ul> <li>&lt;stringbundle&gt;.strings</li>
</ul>
<pre class="eval">var enumerator = document.getElementById('aStringBundleID').strings;
var s = "";
while (enumerator.hasMoreElements()) {
  var property = enumerator.getNext().QueryInterface(Components.interfaces.nsIProperty);
  s += property.name + ' = ' + property.value + ';\n';
}
alert(s);
</pre>
<h4 id="Example_using_JavaScript_1.7_features" name="Example_using_JavaScript_1.7_features">Example using <a href="/en/JavaScript/New_in_JavaScript/1.7" title="en/New_in_JavaScript_1.7">JavaScript 1.7</a> features</h4>
<pre class="eval">// creates a generator iterating over enum's values
function generatorFromSimpleEnumerator(enum, interface) {
  while (enum.hasMoreElements()) {
    yield enum.getNext().QueryInterface(interface);
  }
}
var b = document.getElementById("stringbundleset").firstChild
var props = generatorFromEnumerator(b.strings, Components.interfaces.nsIPropertyElement);
var s = "";
for (let property in props) {
  s += property.key + ' = ' + property.value + ';\n';
}
alert(s);
</pre>
<h3 id="Links" name="Links">Links</h3>
<ul> <li>Code based on <a href="/en/Using_nsIPasswordManager" title="en/Using_nsIPasswordManager">Using_nsIPasswordManager</a></li> <li><a href="/en/XPCOM_Interface_Reference/nsISimpleEnumerator">nsISimpleEnumerator</a></li> <li><a href="/en/XUL/Property/strings" title="en/XUL/Property/strings">XUL:Property:strings</a></li>
</ul>
Revert to this revision