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 506005 of util/collection

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/util_collection
  • Revision title: util/collection
  • Revision id: 506005
  • Created:
  • Creator: jsantell
  • Is current revision? No
  • Comment

Revision Content

Unstable

The util/collection module provides a simple list-like class and utilities for using it.

Usage

A collection is ordered, like an array, but its items are unique, like a set.

Globals

Constructors

Collection(array)

Creates a new collection. The collection is backed by an array.

Parameters

array : array
If array is given, it will be used as the backing array. This way the caller can fully control the collection. Otherwise a new empty array will be used, and no one but the collection will have access to it.

Functions

addCollectionProperty(object, propName, backingArray)

Adds a collection property to the given object. Setting the property to a scalar value empties the collection and adds the value. Setting it to an array empties the collection and adds all the items in the array.

Parameters

object : object
The property will be defined on this object.

propName : string
The name of the property.

backingArray : array
If given, this will be used as the collection's backing array.

Collection

Methods

add(itemOrItems)

Adds a single item or an array of items to the collection. Any items already contained in the collection are ignored.

Parameters

itemOrItems : object
An item or array of items.

Returns

Collection : The Collection.

remove(itemOrItems)

Removes a single item or an array of items from the collection. Any items not contained in the collection are ignored.

Parameters

itemOrItems : object
An item or array of items.

Returns

Collection : The Collection.

Properties

length

The number of items in the collection array.

Revision Source

<div class="note">
 <p>Unstable</p>
</div>
<p><span class="seoSummary">The <code>util/collection</code> module provides a simple list-like class and utilities for using it.</span></p>
<h2>Usage</h2>
<p>A collection is ordered, like an array, but its items are unique, like a set.</p>
<h2>Globals</h2>
<h3>Constructors</h3>
<h4 class="addon-sdk-api-name"><code>Collection(array)</code></h4>
<p>Creates a new collection. The collection is backed by an array.</p>
<h5>Parameters</h5>
<p><strong>array : array</strong><br />
 If <em>array</em> is given, it will be used as the backing array. This way the caller can fully control the collection. Otherwise a new empty array will be used, and no one but the collection will have access to it.</p>
<h3>Functions</h3>
<h4 class="addon-sdk-api-name"><code>addCollectionProperty(object, propName, backingArray)</code></h4>
<p>Adds a collection property to the given object. Setting the property to a scalar value empties the collection and adds the value. Setting it to an array empties the collection and adds all the items in the array.</p>
<h5>Parameters</h5>
<p><strong>object : object</strong><br />
 The property will be defined on this object.</p>
<p><strong>propName : string</strong><br />
 The name of the property.</p>
<p><strong>backingArray : array</strong><br />
 If given, this will be used as the collection's backing array.</p>
<h2>Collection</h2>
<h3>Methods</h3>
<h4 class="addon-sdk-api-name"><code>add(itemOrItems)</code></h4>
<p>Adds a single item or an array of items to the collection. Any items already contained in the collection are ignored.</p>
<h5>Parameters</h5>
<p><strong>itemOrItems : object</strong><br />
 An item or array of items.</p>
<h5>Returns</h5>
<p><strong>Collection</strong> : The Collection.</p>
<h4 class="addon-sdk-api-name"><code>remove(itemOrItems)</code></h4>
<p>Removes a single item or an array of items from the collection. Any items not contained in the collection are ignored.</p>
<h5>Parameters</h5>
<p><strong>itemOrItems : object</strong><br />
 An item or array of items.</p>
<h5>Returns</h5>
<p><strong>Collection</strong> : The Collection.</p>
<h3>Properties</h3>
<h4 class="addon-sdk-api-name"><code>length</code></h4>
<p>The number of items in the collection array.</p>
Revert to this revision