Constructor
new List(…itemopt)
An array-like object that is more conducive to extending.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
item |
* |
<optional> <repeatable> |
Items to add to the list on initialization. |
Example
// Here's an example that will inherit from List and implement a new,
// worthless getLength() method:
function DumbList() {
bp.core.List.apply(this, arguments);
}
DumbList.prototype = Object.create(bp.core.List.prototype);
DumbList.prototype.constructor = DumbList;
DumbList.prototype.getLength = function getLength() {
return this.length;
};
Methods
concat(…list) → {bp.core.List}
Creates a new list with the items from the current list and items from
all other provided lists.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
list |
bp.core.List |
<repeatable> |
Lists to add together. |
Returns:
A new list.
- Type
- bp.core.List
Example
var list1 = new bp.core.List('thing1', 'thing2')
, list2 = list1.concat(new bp.core.List('Bob', 'Dude'));
list2.length // => 4 (contains 'thing1', 'thing2', 'Bob', and 'Dude')
filter(fn, thisArgopt) → {bp.core.List}
Create a new List() based upon the items from the
current list, after the filter function has been applied.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
callback | A callback function to call on with each item in the list. | |
thisArg |
* |
<optional> |
A value to use as "this" when executing the callback. |
Returns:
A new list with the filtered items.
- Type
- bp.core.List
Example
var someList = new bp.core.List('thing1', 'thing2', 'thing3', 3, 4, 5);
// create a new list with only numbers in it (3, 4, 5).
var newList = someList.someList.filter(function(i) {
return typeof i === 'number';
});
map(fn) → {bp.core.List}
Perform a map function on the list.
Parameters:
Name | Type | Description |
---|---|---|
fn |
callback | The function to perform the map operation with. |
Returns:
A new list with the mapped data.
- Type
- bp.core.List
slice(beginopt, endopt) → {bp.core.List}
Create a new List() with the selected slice.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
begin |
number |
<optional> |
0 | The starting point of the slice. |
end |
number |
<optional> |
list.length | The ending point of the slice. |
Returns:
A new List
- Type
- bp.core.List
splice(start, deleteCount, …itemopt)
Splice data in and out of the list.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
start |
number | The index to start changing the list at. | |
deleteCount |
number | How many items should be removed from the list. | |
item |
* |
<optional> <repeatable> |
Optional item(s) to add to the list. |
toArray() → {array}
Returns an array with the items from the list.
Returns:
A new array.
- Type
- array
toJSON() → {array}
Makes the list serializable to JSON.
Returns:
a new array.
- Type
- array