mozilla

Revision 66568 of Using nsISimpleEnumerator

  • Revision slug: Using_nsISimpleEnumerator
  • Revision title: Using nsISimpleEnumerator
  • Revision id: 66568
  • Created:
  • Creator: Nickolay
  • Is current revision? No
  • Comment js1.7 example

Revision Content

Using nsISimpleEnumerator

  • <stringbundle>.strings
var enumerator = document.getElementById('aStringBundleID').strings;
var s = "";
while (enumerator.hasMoreElements()) {
  var property = enumerator.getNext().QueryInterface(Components.interfaces.nsIPropertyElement);
  s += property.key + ' = ' + 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);

Links

Revision Source

<h3 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.nsIPropertyElement);
  s += property.key + ' = ' + property.value + ';\n';
}
alert(s);
</pre>
<h4 name="Example_using_JavaScript_1.7_features"> Example using <a href="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 name="Links"> Links </h3>
<ul><li> Code based on <a href="en/Using_nsIPasswordManager">Using_nsIPasswordManager</a>
</li><li> <a class="external" href="http://www.xulplanet.com/references/xpcomref/ifaces/nsISimpleEnumerator.html">nsISimpleEnumerator</a>
</li><li> <a href="en/XUL/Property/strings">XUL:Property:strings</a>
</li></ul>
Revert to this revision