Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 740341 of util/list

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/util_list
  • Revision title: util/list
  • Revision id: 740341
  • Created:
  • Creator: evold
  • Is current revision? No
  • Comment updated the example to use a require statement

Revision Content

Experimental

Building blocks for composing lists.

List

An ordered collection (also known as a sequence) disallowing duplicate elements. List is composed out of Iterable, therefore it provides custom enumeration behavior that is similar to array (enumerates only on the elements of the list).

List is a base trait and is meant to be part of a composition, since all of its API is private except for the length property.

Examples:

var { List } = require("util/list");
var MyList = List.compose({
  add: function add(item1, item2, /*item3...*/) {
    Array.slice(arguments).forEach(this._add.bind(this));
  },
  remove: function remove(item1, item2, /*item3...*/) {
    Array.slice(arguments).forEach(this._remove.bind(this));
  }
});
MyList('foo', 'bar', 'baz').length == 3;        // true
new MyList('new', 'keyword').length == 2;       // true
MyList.apply(null, [1, 2, 3]).length == 3;      // true
let list = MyList();
list.length == 0;                               // true
list.add(1, 2, 3) == 3;                         // true

Properties

length

Number of elements in this list.

Revision Source

<div class="note">
<p>Experimental</p>
</div>

<p><span class="seoSummary">Building blocks for composing lists.</span></p>

<h2 id="List">List</h2>

<p>An ordered collection (also known as a sequence) disallowing duplicate elements. List is composed out of <code>Iterable</code>, therefore it provides custom enumeration behavior that is similar to array (enumerates only on the elements of the list).</p>

<p>List is a base trait and is meant to be part of a composition, since all of its API is private except for the <code>length</code> property.</p>

<p><strong>Examples:</strong></p>

<pre class="brush: js">
var { List } = require("util/list");
var MyList = List.compose({
  add: function add(item1, item2, /*item3...*/) {
    Array.slice(arguments).forEach(this._add.bind(this));
  },
  remove: function remove(item1, item2, /*item3...*/) {
    Array.slice(arguments).forEach(this._remove.bind(this));
  }
});
MyList('foo', 'bar', 'baz').length == 3;        // true
new MyList('new', 'keyword').length == 2;       // true
MyList.apply(null, [1, 2, 3]).length == 3;      // true
let list = MyList();
list.length == 0;                               // true
list.add(1, 2, 3) == 3;                         // true</pre>

<h3 id="Properties">Properties</h3>

<h4 class="addon-sdk-api-name" id="length"><code>length</code></h4>

<p>Number of elements in this list.</p>
Revert to this revision