Currently, two data types are available: Lists and Arrays. Both represent a sequence of items and aim to have a similar interface to the native Javascript Arrays for the most common operations like push/pop and indexed get/set.
One important limitation is that when you create an Eina collection you must pass the type of object that will be stored. This is required to allow the binding do the correct conversion between Javascript types and C/C++ types due to the former's static nature.
Besides the constructor function, they differ in the way the items are stored underneath. efl.List
are doubly-linked lists, with relatively fast insert/delete operations while efl.Array
objects are contiguous memory regions, with fast data access (compared to Lists) but allowing to insert or delete items only at the extremities of the container.
Syntax
new efl.List(typename); new efl.Array(typename);
Parameters
Return type
The constructor functions receive the name of the type that will be stored on the container. The following types are supported using the respective type name:
The methods and operations below are supported for both types of sequences.
Syntax
var new_container = objA.concat(objC);
Parameters
Return type
Concatenates two containers returning the result as a new container object.
Syntax
var myvar = obj[index];
Parameters
Return type
undefined
- When calling on a container wrapping items of type T. undefined
if no object on that index.
Works like Javascript Array []
operators. The items are 0-indexed, with the first element at index 0 and the last element with index equal to the number of elements of the sequence minus 1.
Usage example:
mylist[42] // Gets the 42nd element mylist[0] // Gets the first element.
undefined
.
Syntax
var index = obj.indexOf(target);
Parameters
Return type
Searches for target
in the container and returns the index if found. If not found, return -1.
Example usage:
// obj = [100, 42, 55, 42] var idx = obj.indexOf(42); // idx = 1 var idx2 = obj.indexOf(1000); // idx2 = -1
Syntax
var index = obj.lastIndexOf(target);
Parameters
Return type
Searches backwards for target
, returning its index if found, or -1 otherwise.
Example code:
// obj = [100, 42, 55, 42] var idx = obj.lastIndexOf(42) // idx = 3 var idx2 = obj.lastIndexOf(0) // idx2 = -1
Syntax
obj.length
Return type
Returns the number of elements on this container.
Example usage:
var last = obj[obj.length - 1]
Syntax
var value = obj.pop();
Return type
undefined
- For containers wrapping items of type T. undefined
if it was an empty space or the container was empty.
Behaves like Javascript Array.pop()
, removing the last element of the list and returning it.
Example code:
// obj is [1,2,3,4,5] var value = obj.pop(); // value now is 5 and obj is [1,2,3,4]
Syntax
var size = obj.push(item)
Parameters
Return type
Works like the Javascript Array.push(item)
, appending the item to the end of the sequence. For lists, a new node is created at the end. For Arrays, the item is set to the end of the array, and it may grow as needed.
The method returns the size of the container after adding the new element.
Usage example:
var mylist = new efl.List("int"); mylist.push(3); var myarray = new efl.Array("string"); var new_size = myarray.push("Foobar");
var obj = new efl.List("float"); obj.push("44"); // CRASH!!!!
Syntax
obj[index] = value; var v = (obj[index] = value);
Parameters
Return type
value
).Works like Javascript indexed setter method. It sets the value at the given index to the given value, generally not changing the container size (see note below). On success, the operation returns the value recently set.
undefined
, and setting the given value in the last position.
var obj = new efl.List("int"); obj[42] = 42; // Obj now has 42 undefined's leading up to 42 in the last position.
Usage example:
var obj = new efl.List("int"); obj.push(3) // [3] obj.push(2) // [3,2] obj[0] = 42; // [42, 2]
Syntax
var x = obj.slice(); var y = obj.slice(startIndex); var z = obj.slice(startIndex, endIndex);
Parameters
Return type
The slice method retrieves portions of the container. The first argument is the index to start the slice operation (default is 0, beginning of the list) and the second argument indicates the index where the extraction should stop, not including it (defaults to the container size). In interval notation, it returns [begin, end)
.
It also performs a shallow copy like concat().
Example usage:
var same = obj.slice() // All elements from obj are in the returned container. var other = obj.slice(1); // Everything but the first element. var another = obj.slice (4, 10); // From the fifth element to the tenth.
Syntax
obj.toString();
Return type
Generates a comma-separated string with the representation of the items in this container.