WWW-www.enlightenment.org pushed a commit to branch master. http://git.enlightenment.org/website/www-content.git/commit/?id=34a88264b984bfd8abc55e45153618c12d63c290
commit 34a88264b984bfd8abc55e45153618c12d63c290 Author: Lauro Moura <lauromo...@expertisesolutions.com.br> Date: Mon Nov 30 14:54:35 2015 -0800 Wiki page containers changed with summary [Methods now in alphabetical order] by Lauro Moura --- pages/api/javascript/eina/containers.txt | 164 +++++++++++++++---------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/pages/api/javascript/eina/containers.txt b/pages/api/javascript/eina/containers.txt index 39b7d53..866baf9 100644 --- a/pages/api/javascript/eina/containers.txt +++ b/pages/api/javascript/eina/containers.txt @@ -30,36 +30,21 @@ The constructor functions receive the name of the type that will be stored on th The methods and operations below are supported for both types of sequences. -=== push(value) === +=== concat(container) === Syntax <code javascript> -var size = obj.push(item) +var new_container = objA.concat(objC); </code> -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: - -<code javascript> -var mylist = new efl.List("int"); -mylist.push(3); -var myarray = new efl.Array("string"); -var new_size = myarray.push("Foobar"); -</code> +Concatenates two containers returning the result as a new container object. It performs a shallow copy of the container. Object **references** are copied (i.e. changes in the object will appear in both containers) and basic types are copied. <note warning> -Although Javascript is weak typed, the binding functions are rather strong typed, doing minimal type conversions, like int to floats. Trying to push an element of a different type from the one provided in the constructor will raise TypeError. -<code javascript> -var obj = new efl.List("float"); -obj.push("44"); // CRASH!!!! -</code> +The concatenation operation will work only on the same type of containers (e.g. lists of ints with lists of ints). Wrong arguments will raise TypeError. </note> -=== container[index] === +=== getter: container[index] === Syntax @@ -80,38 +65,62 @@ mylist[0] // Gets the first element. Trying to access an element with an index out of bounds will return ''undefined''. </note> -=== container[index] = value === +=== indexOf(target) === Syntax <code javascript> -obj[index] = value; -var v = (obj[index] = value); +var index = obj.indexOf(target); </code> -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. +Searches for ''target'' in the container and returns the index if found. If not found, return -1. + +Example usage: -<note important> -Trying to set a value at an index equal or larger than the size of the container will extend the container up to that index and fill value up to the last one with ''undefined'', and setting the given value in the last position. <code javascript> -var obj = new efl.List("int"); -obj[42] = 42; // Obj now has 42 undefined's leading up to 42 in the last position. +// obj = [100, 42, 55, 42] +var idx = obj.indexOf(42); // idx = 1 +var idx2 = obj.indexOf(1000); // idx2 = -1 </code> -</note> -Usage example: +=== lastIndexOf(target) === + +Syntax <code javascript> -var obj = new efl.List("int"); -obj.push(3) // [3] -obj.push(2) // [3,2] -obj[0] = 42; // [42, 2] +var index = obj.lastIndexOf(target); </code> -<note warning> -As with pushing elements, trying to push an element of a different type from the one given to the constructor will raise TypeError. +Searches backwards for ''target'', returning its index if found, or -1 otherwise. + +Example code: + +<code javascript> +// obj = [100, 42, 55, 42] +var idx = obj.lastIndexOf(42) // idx = 3 +var idx2 = obj.lastIndexOf(0) // idx2 = -1 +</code> + +=== length property === + +Syntax + +<code javascript> +obj.length +</code> + +Returns the number of elements on this container. + +<note important> +In pure Javascript Arrays, assigning a number smaller than the size of the container to the length property will delete elements from the container. This behavior is **not** present on eina Arrays or Lists. Trying to assign a number to length will have no effect. </note> +Example usage: + +<code javascript> +var last = obj[obj.length - 1] +</code> + === pop() === Syntax @@ -132,48 +141,65 @@ var value = obj.pop(); // value now is 5 and obj is [1,2,3,4] Trying to pop an item from an empty list will return undefined and leave the list empty. </note> -=== length property === +=== push(value) === Syntax <code javascript> -obj.length +var size = obj.push(item) </code> -Returns the number of elements on this container. +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. -<note important> -In pure Javascript Arrays, assigning a number smaller than the size of the container to the length property will delete elements from the container. This behavior is **not** present on eina Arrays or Lists. Trying to assign a number to length will have no effect. -</note> +The method returns the size of the container after adding the new element. -Example usage: +Usage example: <code javascript> -var last = obj[obj.length - 1] +var mylist = new efl.List("int"); +mylist.push(3); +var myarray = new efl.Array("string"); +var new_size = myarray.push("Foobar"); </code> -=== toString() === +<note warning> +Although Javascript is weak typed, the binding functions are rather strong typed, doing minimal type conversions, like int to floats. Trying to push an element of a different type from the one provided in the constructor will raise TypeError. +<code javascript> +var obj = new efl.List("float"); +obj.push("44"); // CRASH!!!! +</code> +</note> + +=== setter: container[index] = value === Syntax <code javascript> -obj.toString(); +obj[index] = value; +var v = (obj[index] = value); </code> -Generates a comma-separated string with the representation of the items in this container. +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. -=== concat(container) === +<note important> +Trying to set a value at an index equal or larger than the size of the container will extend the container up to that index and fill value up to the last one with ''undefined'', and setting the given value in the last position. +<code javascript> +var obj = new efl.List("int"); +obj[42] = 42; // Obj now has 42 undefined's leading up to 42 in the last position. +</code> +</note> -Syntax +Usage example: <code javascript> -var new_container = objA.concat(objC); +var obj = new efl.List("int"); +obj.push(3) // [3] +obj.push(2) // [3,2] +obj[0] = 42; // [42, 2] </code> -Concatenates two containers returning the result as a new container object. It performs a shallow copy of the container. Object **references** are copied (i.e. changes in the object will appear in both containers) and basic types are copied. - <note warning> -The concatenation operation will work only on the same type of containers (e.g. lists of ints with lists of ints). Wrong arguments will raise TypeError. +As with pushing elements, trying to push an element of a different type from the one given to the constructor will raise TypeError. </note> === slice([begin,[end]]) === @@ -198,38 +224,12 @@ var other = obj.slice(1); // Everything but the first element. var another = obj.slice (4, 10); // From the fifth element to the tenth. </code> -=== indexOf(target) === - -Syntax - -<code javascript> -var index = obj.indexOf(target); -</code> - -Searches for ''target'' in the container and returns the index if found. If not found, return -1. - -Example usage: - -<code javascript> -// obj = [100, 42, 55, 42] -var idx = obj.indexOf(42); // idx = 1 -var idx2 = obj.indexOf(1000); // idx2 = -1 -</code> - -=== lastIndexOf(target) === +=== toString() === Syntax <code javascript> -var index = obj.lastIndexOf(target); +obj.toString(); </code> -Searches backwards for ''target'', returning its index if found, or -1 otherwise. - -Example code: - -<code javascript> -// obj = [100, 42, 55, 42] -var idx = obj.lastIndexOf(42) // idx = 3 -var idx2 = obj.lastIndexOf(0) // idx2 = -1 -</code> \ No newline at end of file +Generates a comma-separated string with the representation of the items in this container. \ No newline at end of file --