diff --git a/en/application-dev/reference/apis/js-apis-arraylist.md b/en/application-dev/reference/apis/js-apis-arraylist.md index 0618e40a4327d72455405588df46c9f91f7262e4..d98422b678ea658dbe4092dc9247ca4bb551f5cc 100644 --- a/en/application-dev/reference/apis/js-apis-arraylist.md +++ b/en/application-dev/reference/apis/js-apis-arraylist.md @@ -40,10 +40,23 @@ A constructor used to create an **ArrayList** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The ArrayList's constructor cannot be directly invoked. | + **Example** ```ts let arrayList = new ArrayList(); +try { + let arrayList2 = ArrayList(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -67,6 +80,14 @@ Adds an element at the end of this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts @@ -76,7 +97,13 @@ Adds an element at the end of this container. let b = [1, 2, 3]; let result2 = arrayList.add(b); let c = {name: "Dylon", age: "13"}; - let result3 = arrayList.add(false); + let result3 = arrayList.add(c); + let result4 = arrayList.add(false); + try { + arrayList.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. + } catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); + } ``` ### insert @@ -94,6 +121,15 @@ Inserts an element at the specified position in this container. | element | T | Yes| Target element.| | index | number | Yes| Index of the position where the element is to be inserted.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The insert method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -101,6 +137,21 @@ let arrayList = new ArrayList(); arrayList.insert("A", 0); arrayList.insert(0, 1); arrayList.insert(true, 2); +try { + arrayList.insert.bind({}, 1, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + let res = arrayList.insert (8, 11); // Trigger an out-of-bounds exception. +} catch (err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + let res = arrayList.insert("a", "b"); // Trigger a type exception. +} catch (err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### has @@ -123,6 +174,14 @@ Checks whether this container has the specified element. | -------- | -------- | | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -130,6 +189,11 @@ let arrayList = new ArrayList(); let result = arrayList.has("squirrel"); arrayList.add("squirrel"); let result1 = arrayList.has("squirrel"); +try { + arrayList.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getIndexOf @@ -152,6 +216,14 @@ Obtains the index of the first occurrence of the specified element in this conta | -------- | -------- | | number | Returns the position index if obtained; returns **-1** if the specified element is not found.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOf method cannot be bound. | + **Example** ```ts @@ -164,6 +236,11 @@ arrayList.add(1); arrayList.add(2); arrayList.add(4); let result = arrayList.getIndexOf(2); +try { + arrayList.getIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getLastIndexOf @@ -186,6 +263,14 @@ Obtains the index of the last occurrence of the specified element in this contai | -------- | -------- | | number | Returns the position index if obtained; returns **-1** if the specified element is not found.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLastIndexOf method cannot be bound. | + **Example** ```ts @@ -198,6 +283,11 @@ arrayList.add(1); arrayList.add(2); arrayList.add(4); let result = arrayList.getLastIndexOf(2); +try { + arrayList.getLastIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeByIndex @@ -220,6 +310,15 @@ Removes an element with the specified position from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeByIndex method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -230,6 +329,21 @@ arrayList.add(5); arrayList.add(2); arrayList.add(4); let result = arrayList.removeByIndex(2); +try { + arrayList.removeByIndex.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + arrayList.removeByIndex("a"); // Trigger a type exception. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + arrayList.removeByIndex(8); // Trigger an out-of-bounds exception. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### remove @@ -252,6 +366,14 @@ Removes the first occurrence of the specified element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -261,6 +383,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); let result = arrayList.remove(2); +try { + arrayList.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeByRange @@ -278,6 +405,15 @@ Removes from this container all of the elements within a range, including the el | fromIndex | number | Yes| Index of the start position.| | toIndex | number | Yes| Index of the end position.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeByRange method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -287,8 +423,16 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); arrayList.removeByRange(2, 4); -arrayList.removeByRange(4, 3); -arrayList.removeByRange(2, 6); +try { + arrayList.removeByRange.bind({}, 2, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + arrayList.removeByRange(8, 4); // Trigger an out-of-bounds exception. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### replaceAllElements @@ -315,6 +459,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | arrlist | ArrayList<T> | No| Instance that invokes the **replaceAllElements** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The replaceAllElements method cannot be bound. | + **Example** ```ts @@ -329,6 +481,13 @@ arrayList.replaceAllElements((value: number, index: number)=> { arrayList.replaceAllElements((value: number, index: number) => { return value = value - 2; }); +try { + arrayList.replaceAllElements.bind({}, (value: number, index: number)=> { + return value = 2 * value; + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### forEach @@ -355,6 +514,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | arrlist | ArrayList<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -366,6 +533,13 @@ arrayList.add(4); arrayList.forEach((value, index) => { console.log(`value:${value}`, index); }); +try { + arrayList.forEach.bind({}, (value, index) => { + console.log(`value:${value}`, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### sort @@ -389,6 +563,14 @@ comparator | firstValue | T | Yes| Previous element.| | secondValue | T | Yes| Next element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The sort method cannot be bound. | + **Example** ```ts @@ -400,6 +582,11 @@ arrayList.add(4); arrayList.sort((a: number, b: number) => a - b); arrayList.sort((a: number, b: number) => b - a); arrayList.sort(); +try { + arrayList.sort.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### subArrayList @@ -423,6 +610,15 @@ Obtains elements within a range in this container, including the element at the | -------- | -------- | | ArrayList<T> | New **ArrayList** instance obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The subArrayList method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -434,6 +630,16 @@ arrayList.add(4); let result1 = arrayList.subArrayList(2, 4); let result2 = arrayList.subArrayList(4, 3); let result3 = arrayList.subArrayList(2, 6); +try { + arrayList.subArrayList.bind({}, 2, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + arrayList.subArrayList(6, 4); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### clear @@ -444,6 +650,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -453,6 +667,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); arrayList.clear(); +try { + arrayList.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### clone @@ -470,6 +689,14 @@ Clones this container and returns a copy. The modification to the copy does not | -------- | -------- | | ArrayList<T> | New **ArrayList** instance obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clone method cannot be bound. | + **Example** ```ts @@ -479,6 +706,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); let result = arrayList.clone(); +try { + arrayList.clone.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getCapacity @@ -495,6 +727,14 @@ Obtains the capacity of this container. | -------- | -------- | | number | Capacity obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getCapacity method cannot be bound. | + **Example** ```ts @@ -504,6 +744,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); let result = arrayList.getCapacity(); +try { + arrayList.getCapacity.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### convertToArray @@ -520,6 +765,14 @@ Converts this container into an array. | -------- | -------- | | Array<T> | Array obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The convertToArray method cannot be bound. | + **Example** ```ts @@ -529,6 +782,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); let result = arrayList.convertToArray(); +try { + arrayList.convertToArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### isEmpty @@ -545,6 +803,14 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts @@ -554,6 +820,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); let result = arrayList.isEmpty(); +try { + arrayList.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### increaseCapacityTo @@ -570,6 +841,14 @@ Increases the capacity of this container. | -------- | -------- | -------- | -------- | | newCapacity | number | Yes| New capacity.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The increaseCapacityTo method cannot be bound. | + **Example** ```ts @@ -580,6 +859,11 @@ arrayList.add(5); arrayList.add(4); arrayList.increaseCapacityTo(2); arrayList.increaseCapacityTo(8); +try { + arrayList.increaseCapacityTo.bind({}, 5)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### trimToCurrentLength @@ -590,6 +874,14 @@ Trims the capacity of this container to its current length. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The trimToCurrentLength method cannot be bound. | + **Example** ```ts @@ -599,6 +891,11 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); arrayList.trimToCurrentLength(); +try { + arrayList.trimToCurrentLength.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### [Symbol.iterator] @@ -615,6 +912,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -636,4 +941,9 @@ while(temp != undefined) { console.log(`value:${temp}`); temp = iter.next().value; } +try { + arrayList[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-deque.md b/en/application-dev/reference/apis/js-apis-deque.md index 973cdfb78725ba03576d7cc6a561c71e6930aeb2..594984e1deb513a21c165c04d0d7d95a918a8766 100644 --- a/en/application-dev/reference/apis/js-apis-deque.md +++ b/en/application-dev/reference/apis/js-apis-deque.md @@ -39,10 +39,23 @@ A constructor used to create a **Deque** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The Deque's constructor cannot be directly invoked. | + **Example** ```ts let deque = new Deque(); +try { + let deque2 = Deque(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### insertFront @@ -59,6 +72,14 @@ Inserts an element at the front of this container. | -------- | -------- | -------- | -------- | | element | T | Yes| Target element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The insertFront method cannot be bound. | + **Example** ```ts @@ -68,7 +89,13 @@ deque.insertFront(1); let b = [1, 2, 3]; deque.insertFront(b); let c = {name : "Dylon", age : "13"}; +deque.insertFront(c); deque.insertFront(false); +try { + deque.insertFront.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### insertEnd @@ -85,6 +112,14 @@ Inserts an element at the end of this container. | -------- | -------- | -------- | -------- | | element | T | Yes| Target element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The insertEnd method cannot be bound. | + **Example** ```ts @@ -94,7 +129,13 @@ deque.insertEnd(1); let b = [1, 2, 3]; deque.insertEnd(b); let c = {name : "Dylon", age : "13"}; +deque.insertEnd(c); deque.insertEnd(false); +try { + deque.insertEnd.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### has @@ -117,6 +158,14 @@ Checks whether this container has the specified element. | -------- | -------- | | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -124,6 +173,11 @@ let deque = new Deque(); let result = deque.has("squirrel"); deque.insertFront("squirrel"); let result1 = deque.has("squirrel"); +try { + deque.has.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### popFirst @@ -140,6 +194,14 @@ Removes the first element of this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The popFirst method cannot be bound. | + **Example** ```ts @@ -150,6 +212,11 @@ deque.insertEnd(5); deque.insertFront(2); deque.insertFront(4); let result = deque.popFirst(); +try { + deque.popFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### popLast @@ -166,6 +233,14 @@ Removes the last element of this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The popLast method cannot be bound. | + **Example** ```ts @@ -176,6 +251,11 @@ deque.insertFront(5); deque.insertFront(2); deque.insertFront(4); let result = deque.popLast(); +try { + deque.popLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### forEach @@ -202,6 +282,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | deque | Deque<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -213,6 +301,13 @@ deque.insertEnd(4); deque.forEach((value, index) => { console.log("value:" + value, index); }); +try { + deque.forEach.bind({}, (value, index) => { + console.log("value:" + value, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getFirst @@ -229,6 +324,14 @@ Obtains the first element of this container. | -------- | -------- | | T | Element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getFirst method cannot be bound. | + **Example** ```ts @@ -238,6 +341,11 @@ deque.insertEnd(4); deque.insertFront(5); deque.insertFront(4); let result = deque.getFirst(); +try { + deque.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getLast @@ -254,6 +362,14 @@ Obtains the last element of this container. | -------- | -------- | | T | Element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLast method cannot be bound. | + **Example** ```ts @@ -263,6 +379,11 @@ deque.insertFront(4); deque.insertFront(5); deque.insertFront(4); let result = deque.getLast(); +try { + deque.getLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### [Symbol.iterator] @@ -279,6 +400,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts let deque = new Deque(); @@ -299,4 +428,9 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + deque[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-hashmap.md b/en/application-dev/reference/apis/js-apis-hashmap.md index 5cf52af02dd7e1c36469882706ef2e0533cc5a5c..f3deddcc499cfa9cb3b32c5b3951664dfa3d44cb 100644 --- a/en/application-dev/reference/apis/js-apis-hashmap.md +++ b/en/application-dev/reference/apis/js-apis-hashmap.md @@ -41,10 +41,23 @@ A constructor used to create a **HashMap** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The HashMap's constructor cannot be directly invoked. | + **Example** ```ts let hashMap = new HashMap(); +try { + let hashMap2 = HashMap(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -62,11 +75,24 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const hashMap = new HashMap(); let result = hashMap.isEmpty(); +try { + hashMap.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -90,6 +116,14 @@ Checks whether this container contains the specified key. | -------- | -------- | | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasKey method cannot be bound. | + **Example** ```ts @@ -97,6 +131,11 @@ let hashMap = new HashMap(); let result = hashMap.hasKey("squirrel"); hashMap.set("squirrel", 123); let result1 = hashMap.hasKey("squirrel"); +try { + hashMap.hasKey.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -120,6 +159,14 @@ Checks whether this container contains the specified value. | -------- | -------- | | boolean | Returns **true** if the specified value is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasValue method cannot be bound. | + **Example** ```ts @@ -127,6 +174,11 @@ let hashMap = new HashMap(); let result = hashMap.hasValue(123); hashMap.set("squirrel", 123); let result1 = hashMap.hasValue(123); +try { + hashMap.hasValue.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -150,6 +202,14 @@ Obtains the value of the specified key in this container. | -------- | -------- | | V | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The get method cannot be bound. | + **Example** ```ts @@ -157,6 +217,11 @@ let hashMap = new HashMap(); hashMap.set("squirrel", 123); hashMap.set("sparrow", 356); let result = hashMap.get("sparrow"); +try { + hashMap.get.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -174,6 +239,14 @@ Adds all elements in a **HashMap** instance to this container. | -------- | -------- | -------- | -------- | | map | HashMap<K, V> | Yes| **HashMap** instance whose elements are to be added to the current container.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The setAll method cannot be bound. | + **Example** ```ts @@ -182,6 +255,11 @@ hashMap.set("squirrel", 123); hashMap.set("sparrow", 356); let newHashMap = new HashMap(); hashMap.setAll(newHashMap); +try { + hashMap.setAll.bind({}, newHashMap)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -206,11 +284,24 @@ Adds an element to this container. | -------- | -------- | | Object | Container that contains the new element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The set method cannot be bound. | + **Example** ```ts let hashMap = new HashMap(); let result = hashMap.set("squirrel", 123); +try { + hashMap.set.bind({}, "squirrel", 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -234,6 +325,14 @@ Removes an element with the specified key from this container. | -------- | -------- | | V | Value of the element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -241,6 +340,11 @@ let hashMap = new HashMap(); hashMap.set("squirrel", 123); hashMap.set("sparrow", 356); let result = hashMap.remove("sparrow"); +try { + hashMap.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -252,6 +356,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -259,6 +371,11 @@ let hashMap = new HashMap(); hashMap.set("squirrel", 123); hashMap.set("sparrow", 356); hashMap.clear(); +try { + hashMap.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -276,6 +393,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<K> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The keys method cannot be bound. | + **Example** ```ts @@ -288,6 +413,11 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + hashMap.keys.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -305,6 +435,14 @@ Obtains an iterator that contains all the values in this container. | -------- | -------- | | IterableIterator<V> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The values method cannot be bound. | + **Example** ```ts @@ -317,6 +455,11 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + hashMap.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -341,12 +484,25 @@ Replaces an element in this container. | -------- | -------- | | boolean | Returns **true** if the element is replaced successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The replace method cannot be bound. | + **Example** ```ts let hashMap = new HashMap(); hashMap.set("sparrow", 123); let result = hashMap.replace("sparrow", 357); +try { + hashMap.replace.bind({}, "sparrow", 357)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -372,6 +528,14 @@ callbackfn | key | K | No| Key of the element that is currently traversed.| | map | HashMap<K, V> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -381,6 +545,13 @@ hashMap.set("gull", 357); hashMap.forEach((value, key) => { console.log("value:" + value, key); }); +try { + hashMap.forEach.bind({}, (value, key) => { + console.log("value:" + value, key); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -398,6 +569,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<[K, V]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The entries method cannot be bound. | + **Example** ```ts @@ -411,6 +590,11 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + hashMap.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -428,6 +612,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<[K, V]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts let hashMap = new HashMap(); @@ -448,4 +640,9 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + hashMap[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-hashset.md b/en/application-dev/reference/apis/js-apis-hashset.md index 6568c856e715a5f86da527aea4c5ce3888537bc5..09cd4c914ad0c512f65f7ad05c1552ef6b29f90a 100644 --- a/en/application-dev/reference/apis/js-apis-hashset.md +++ b/en/application-dev/reference/apis/js-apis-hashset.md @@ -49,10 +49,23 @@ A constructor used to create a **HashSet** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The HashSet's constructor cannot be directly invoked. | + **Example** ```ts let hashSet = new HashSet(); +try { + let hashSet2 = HashSet(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -70,11 +83,24 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const hashSet = new HashSet(); let result = hashSet.isEmpty(); +try { + hashSet.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -98,6 +124,14 @@ Checks whether this container contains the specified element. | -------- | -------- | | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -105,6 +139,11 @@ let hashSet = new HashSet(); let result = hashSet.has("squirrel"); hashSet.add("squirrel"); let result1 = hashSet.has("squirrel"); +try { + hashSet.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -128,11 +167,24 @@ Adds an element to this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts let hashSet = new HashSet(); let result = hashSet.add("squirrel"); +try { + hashSet.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -156,6 +208,14 @@ Removes an element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -163,6 +223,11 @@ let hashSet = new HashSet(); hashSet.add("squirrel"); hashSet.add("sparrow"); let result = hashSet.remove("sparrow"); +try { + hashSet.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -174,6 +239,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -181,6 +254,11 @@ let hashSet = new HashSet(); hashSet.add("squirrel"); hashSet.add("sparrow"); hashSet.clear(); +try { + hashSet.remove.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -198,6 +276,14 @@ Obtains an iterator that contains all the values in this container. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The values method cannot be bound. | + **Example** ```ts @@ -209,7 +295,12 @@ let temp = iter.next().value; while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; -} +} +try { + hashSet.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -235,6 +326,14 @@ callbackfn | key | T | No| Key of the element that is currently traversed (same as **value**).| | set | HashSet<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -244,6 +343,13 @@ hashSet.add("squirrel"); hashSet.forEach((value, key) => { console.log("value:" + value, key); }); +try { + hashSet.forEach.bind({}, (value, key) => { + console.log("value:" + value, key); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -260,6 +366,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<[T, T]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The entries method cannot be bound. | + **Example** ```ts @@ -273,6 +387,11 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + hashSet.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -290,6 +409,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -309,4 +436,9 @@ while(temp != undefined) { console.log("value: " + temp); temp = iter.next().value; } +try { + hashSet[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-lightweightmap.md b/en/application-dev/reference/apis/js-apis-lightweightmap.md index 4ff765d9cf8cefcbd3682d7cd9dbd216400d21cb..f2ab94b72b0538f83cd21642081172cfb19b3cb1 100644 --- a/en/application-dev/reference/apis/js-apis-lightweightmap.md +++ b/en/application-dev/reference/apis/js-apis-lightweightmap.md @@ -22,8 +22,6 @@ This topic uses the following to identify the use of generics: import LightWeightMap from '@ohos.util.LightWeightMap'; ``` - - ## LightWeightMap ### Attributes @@ -43,10 +41,24 @@ A constructor used to create a **LightWeightMap** instance. **System capability**: SystemCapability.Utils.Lang + +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The LightWeightMap's constructor cannot be directly invoked. | + **Example** ```ts let lightWeightMap = new LightWeightMap(); +try { + let lightWeightMap2 = LightWeightMap(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -64,11 +76,24 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const lightWeightMap = new LightWeightMap(); let result = lightWeightMap.isEmpty(); +try { + lightWeightMap.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -92,6 +117,14 @@ Checks whether this container contains all elements of the specified **LightWeig | -------- | -------- | | boolean | Returns **true** if all the elements in the specified **LightWeightMap** instance are contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasAll method cannot be bound. | + **Example** ```ts @@ -101,6 +134,11 @@ lightWeightMap.set("sparrow", 356); let map = new LightWeightMap(); map.set("sparrow", 356); let result = lightWeightMap.hasAll(map); +try { + lightWeightMap.hasAll.bind({}, map)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -124,6 +162,14 @@ Checks whether this container contains the specified key. | -------- | -------- | | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasKey method cannot be bound. | + **Example** ```ts @@ -132,6 +178,11 @@ let result = lightWeightMap.hasKey; lightWeightMap.hasKey("squirrel"); lightWeightMap.set("squirrel", 123); let result1 = lightWeightMap.hasKey("squirrel"); +try { + lightWeightMap.hasKey.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -155,6 +206,14 @@ Checks whether this container contains the specified value. | -------- | -------- | | boolean | Returns **true** if the specified value is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasValue method cannot be bound. | + **Example** ```ts @@ -162,6 +221,11 @@ let lightWeightMap = new LightWeightMap(); let result = lightWeightMap.hasValue(123); lightWeightMap.set("squirrel", 123); let result1 = lightWeightMap.hasValue(123); +try { + lightWeightMap.hasValue.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -173,6 +237,14 @@ Increases the capacity of this container. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The increaseCapacityTo method cannot be bound. | + **Parameters** | Name| Type| Mandatory| Description| @@ -184,6 +256,11 @@ Increases the capacity of this container. ```ts let lightWeightMap = new LightWeightMap(); lightWeightMap.increaseCapacityTo(10); +try { + lightWeightMap.increaseCapacityTo.bind({}, 10)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -207,6 +284,14 @@ Obtains the value of the specified key in this container. | -------- | -------- | | V | Value of the key.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The get method cannot be bound. | + **Example** ```ts @@ -214,6 +299,11 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let result = lightWeightMap.get("sparrow"); +try { + lightWeightMap.get.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -237,6 +327,14 @@ Obtains the index of the first occurrence of an element with the specified key i | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOfKey method cannot be bound. | + **Example** ```ts @@ -244,6 +342,11 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let result = lightWeightMap.getIndexOfKey("sparrow"); +try { + lightWeightMap.getIndexOfKey.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -267,6 +370,14 @@ Obtains the index of the first occurrence of an element with the specified value | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOfValue method cannot be bound. | + **Example** ```ts @@ -274,6 +385,11 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let result = lightWeightMap.getIndexOfValue(123); +try { + lightWeightMap.getIndexOfValue.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -297,6 +413,15 @@ Obtains the key of an element at the specified position in this container. | -------- | -------- | | K | Returns the key if obtained; returns **undefined** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getKeyAt method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -304,6 +429,16 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let result = lightWeightMap.getKeyAt(1); +try { + lightWeightMap.getKeyAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + lightWeightMap.getKeyAt(6)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -321,6 +456,14 @@ Adds all elements in a **LightWeightMap** instance to this container. | -------- | -------- | -------- | -------- | | map | LightWeightMap<K, V> | Yes| **LightWeightMap** instance whose elements are to be added to the current container.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The setAll method cannot be bound. | + **Example** ```ts @@ -329,6 +472,11 @@ lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let map = new LightWeightMap(); lightWeightMap.setAll(map); +try { + lightWeightMap.setAll.bind({}, map)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -352,11 +500,24 @@ Adds an element to this container. | -------- | -------- | | Object | Container that contains the new element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The set method cannot be bound. | + **Example** ```ts let lightWeightMap = new LightWeightMap(); let result = lightWeightMap.set("squirrel", 123); +try { + lightWeightMap.set.bind({}, "squirrel", 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -380,6 +541,14 @@ Removes an element with the specified key from this container. | -------- | -------- | | V | Value of the element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -387,6 +556,11 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); lightWeightMap.remove("sparrow"); +try { + lightWeightMap.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -410,6 +584,14 @@ Removes an element at the specified position from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeAt method cannot be bound. | + **Example** ```ts @@ -417,6 +599,11 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let result = lightWeightMap.removeAt(1); +try { + lightWeightMap.removeAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -441,6 +628,15 @@ Sets a value for an element at the specified position in this container. | -------- | -------- | | boolean | Returns **true** if the value is set successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The setValueAt method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -448,6 +644,16 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); lightWeightMap.setValueAt(1, 3546); +try { + lightWeightMap.setValueAt.bind({}, 1, 3546)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + lightWeightMap.setValueAt(6, 3546); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -471,6 +677,15 @@ Obtains the value of an element at the specified position in this container. | -------- | -------- | | V | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getValueAt method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -478,6 +693,16 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); let result = lightWeightMap.getValueAt(1); +try { + lightWeightMap.getValueAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + lightWeightMap.getValueAt(6); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -489,6 +714,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -496,6 +729,11 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("squirrel", 123); lightWeightMap.set("sparrow", 356); lightWeightMap.clear(); +try { + lightWeightMap.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -513,6 +751,14 @@ Obtains an iterator that contains all the keys in this container. | -------- | -------- | | IterableIterator<K> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The keys method cannot be bound. | + **Example** ```ts @@ -525,6 +771,11 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + lightWeightMap.keys.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -542,6 +793,14 @@ Obtains an iterator that contains all the values in this container. | -------- | -------- | | IterableIterator<V> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The values method cannot be bound. | + **Example** ```ts @@ -553,7 +812,12 @@ let temp = iter.next().value; while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; -} +} +try { + lightWeightMap.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -579,6 +843,14 @@ callbackfn | key | K | No| Key of the element that is currently traversed.| | map | LightWeightMap<K, V> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -588,6 +860,13 @@ lightWeightMap.set("gull", 357); lightWeightMap.forEach((value, key) => { console.log("value:" + value, key); }); +try { + lightWeightMap.forEach.bind({}, (value, key) => { + console.log("value:" + value, key); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -605,6 +884,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<[K, V]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The entries method cannot be bound. | + **Example** ```ts @@ -618,6 +905,11 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + lightWeightMap.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### toString @@ -634,14 +926,27 @@ Concatenates the elements in this container into a string and returns the string | -------- | -------- | | String | String obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The toString method cannot be bound. | + **Example** - ```ts - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("squirrel", 123); - lightWeightMap.set("sparrow", 356); - let iter = lightWeightMap.toString(); - ``` +```ts +let lightWeightMap = new LightWeightMap(); +lightWeightMap.set("squirrel", 123); +lightWeightMap.set("sparrow", 356); +let iter = lightWeightMap.toString(); +try { + lightWeightMap.toString.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +``` ### [Symbol.iterator] @@ -657,6 +962,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<[K, V]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -678,4 +991,9 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + lightWeightMap[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-lightweightset.md b/en/application-dev/reference/apis/js-apis-lightweightset.md index d64a40d1b65854d3f97ba399c6426b94b9c71bf0..f5cfbde6cb11daf8884e3c5cf5818fbccc9475a6 100644 --- a/en/application-dev/reference/apis/js-apis-lightweightset.md +++ b/en/application-dev/reference/apis/js-apis-lightweightset.md @@ -44,10 +44,23 @@ A constructor used to create a **LightWeightSet** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The LightWeightSet's constructor cannot be directly invoked. | + **Example** ```ts let lightWeightSet = new LightWeightSet(); +try { + let lightWeightSet2 = LightWeightSet(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -65,11 +78,24 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const lightWeightSet = new LightWeightSet(); let result = lightWeightSet.isEmpty(); +try { + lightWeightSet.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### add @@ -92,11 +118,24 @@ Adds an element to this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts let lightWeightSet = new LightWeightSet(); let result = lightWeightSet.add("squirrel"); +try { + lightWeightSet.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -114,6 +153,14 @@ Adds all elements in a **LightWeightSet** instance to this container. | -------- | -------- | -------- | -------- | | set | LightWeightSet<T> | Yes| **LightWeightSet** instance whose elements are to be added to the current container.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The addAll method cannot be bound. | + **Example** ```ts @@ -123,6 +170,11 @@ lightWeightSet.add("sparrow"); let set = new LightWeightSet(); set.add("gull"); let result = lightWeightSet.addAll(set); +try { + lightWeightSet.addAll.bind({}, set)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -146,6 +198,14 @@ Checks whether this container contains all elements of the specified **LightWeig | -------- | -------- | | boolean | Returns **true** if all the elements in the specified **LightWeightSet** instance are contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasAll method cannot be bound. | + **Example** ```ts @@ -155,6 +215,11 @@ lightWeightSet.add("sparrow"); let set = new LightWeightSet(); set.add("sparrow"); let result = lightWeightSet.hasAll(set); +try { + lightWeightSet.hasAll.bind({}, set)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -178,6 +243,14 @@ Checks whether this container has the specified key. | -------- | -------- | | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -185,6 +258,11 @@ let lightWeightSet = new LightWeightSet(); let result = lightWeightSet.has(123); lightWeightSet.add(123); result = lightWeightSet.has(123); +try { + lightWeightSet.has.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -208,6 +286,14 @@ Checks whether this container contains objects of the same type as the specified | -------- | -------- | | boolean | Returns **true** if the container contains objects of the same type as the specified **obj**; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The equal method cannot be bound. | + **Example** ```ts @@ -216,6 +302,11 @@ lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let obj = ["squirrel", "sparrow"]; let result = lightWeightSet.equal(obj); +try { + lightWeightSet.equal.bind({}, obj)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -233,11 +324,30 @@ Increases the capacity of this container. | -------- | -------- | -------- | -------- | | minimumCapacity | number | Yes| Minimum number of elements to accommodate in the container.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The increaseCapacityTo method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts let lightWeightSet = new LightWeightSet(); lightWeightSet.increaseCapacityTo(10); +try { + lightWeightSet.increaseCapacityTo.bind({}, 10)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + lightWeightSet.increaseCapacityTo(2); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -261,6 +371,14 @@ Obtains the position index of the element with the specified key in this contain | -------- | -------- | | number | Position index of the element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOf method cannot be bound. | + **Example** ```ts @@ -268,6 +386,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let result = lightWeightSet.getIndexOf("sparrow"); +try { + lightWeightSet.getIndexOf.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -291,6 +414,14 @@ Removes an element of the specified key from this container. | -------- | -------- | | T | Value of the element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -298,6 +429,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let result = lightWeightSet.remove("sparrow"); +try { + lightWeightSet.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -321,6 +457,14 @@ Removes the element at the specified position from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeAt method cannot be bound. | + **Example** ```ts @@ -328,6 +472,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let result = lightWeightSet.removeAt(1); +try { + lightWeightSet.removeAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -351,6 +500,14 @@ Obtains the value of the element at the specified position in this container. | -------- | -------- | | T | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getValueAt method cannot be bound. | + **Parameters** ```ts @@ -358,6 +515,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let result = lightWeightSet.getValueAt(1); +try { + lightWeightSet.getValueAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -369,6 +531,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -376,6 +546,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); lightWeightSet.clear(); +try { + lightWeightSet.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -393,6 +568,14 @@ Obtains a string that contains all elements in this container. | -------- | -------- | | String | String obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The toString method cannot be bound. | + **Example** ```ts @@ -400,6 +583,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let result = lightWeightSet.toString(); +try { + lightWeightSet.toString.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -417,6 +605,14 @@ Obtains an array that contains all objects in this container. | -------- | -------- | | Array<T> | Array obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The toArray method cannot be bound. | + **Example** ```ts @@ -424,6 +620,11 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); let result = lightWeightSet.toArray(); +try { + lightWeightSet.toArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -441,6 +642,14 @@ Obtains an iterator that contains all the values in this container. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The values method cannot be bound. | + **Example** ```ts @@ -453,6 +662,11 @@ while(index < lightWeightSet.length) { console.log(JSON.stringify(iter.next().value)); index++; } +try { + lightWeightSet.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -478,6 +692,14 @@ callbackfn | key| T | No| Key of the element that is currently traversed (same as **value**).| | set | LightWeightSet<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -487,6 +709,13 @@ lightWeightSet.add("gull"); lightWeightSet.forEach((value, key) => { console.log("value:" + value, key); }); +try { + lightWeightSet.forEach.bind({}, (value, key) => { + console.log("value:" + value, key); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -504,6 +733,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<[T, T]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The entries method cannot be bound. | + **Example** ```ts @@ -516,6 +753,11 @@ while(index < lightWeightSet.length) { console.log(JSON.stringify(iter.next().value)); index++; } +try { + lightWeightSet.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -533,6 +775,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -552,4 +802,9 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + lightWeightSet[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-linkedlist.md b/en/application-dev/reference/apis/js-apis-linkedlist.md index 3265367a954c1ce027591bc056827717e889339b..81b7ee076547f3ac3acd72fb3267d8e84265e2b3 100644 --- a/en/application-dev/reference/apis/js-apis-linkedlist.md +++ b/en/application-dev/reference/apis/js-apis-linkedlist.md @@ -43,11 +43,24 @@ A constructor used to create a **LinkedList** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The LinkedList's constructor cannot be directly invoked. | + **Example** ```ts let linkedList = new LinkedList(); +try { + let linkedList2 = LinkedList(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -71,6 +84,14 @@ Adds an element at the end of this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts @@ -78,9 +99,15 @@ let linkedList = new LinkedList(); let result = linkedList.add("a"); let result1 = linkedList.add(1); let b = [1, 2, 3]; -linkedList.add(b); +let result2 = linkedList.add(b); let c = {name : "Dylon", age : "13"}; -let result3 = linkedList.add(false); +let result3 = linkedList.add(c); +let result4 = linkedList.add(false); +try { + linkedList.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### addFirst @@ -97,6 +124,14 @@ Adds an element at the top of this container. | -------- | -------- | -------- | -------- | | element | T | Yes| Target element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The addFirst method cannot be bound. | + **Example** ```ts @@ -106,7 +141,13 @@ linkedList.addFirst(1); let b = [1, 2, 3]; linkedList.addFirst(b); let c = {name : "Dylon", age : "13"}; +linkedList.addFirst(c); linkedList.addFirst(false); +try { + linkedList.addFirst.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### insert @@ -124,6 +165,15 @@ Inserts an element at the specified position in this container. | element | T | Yes| Target element.| | index | number | Yes| Index of the position where the element is to be inserted.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The insert method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -131,6 +181,16 @@ let linkedList = new LinkedList(); linkedList.insert(0, "A"); linkedList.insert(1, 0); linkedList.insert(2, true); +try { + linkedList.insert.bind({}, 3, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + linkedList.insert(6, "b"); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### has @@ -153,6 +213,14 @@ Checks whether this container has the specified element. | -------- | -------- | | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -160,6 +228,11 @@ let linkedList = new LinkedList(); let result1 = linkedList.has("squirrel"); linkedList.add("squirrel"); let result = linkedList.has("squirrel"); +try { + linkedList.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### get @@ -182,6 +255,14 @@ Obtains an element at the specified position in this container. | -------- | -------- | | T | Element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The get method cannot be bound. | + **Example** ```ts @@ -194,6 +275,11 @@ linkedList.add(1); linkedList.add(2); linkedList.add(4); let result = linkedList.get(2); +try { + linkedList.get.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getLastIndexOf @@ -216,6 +302,14 @@ Obtains the index of the last occurrence of the specified element in this contai | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLastIndexOf method cannot be bound. | + **Example** ```ts @@ -228,6 +322,11 @@ linkedList.add(1); linkedList.add(2); linkedList.add(4); let result = linkedList.getLastIndexOf(2); +try { + linkedList.getLastIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getIndexOf @@ -250,6 +349,14 @@ Obtains the index of the first occurrence of the specified element in this conta | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOf method cannot be bound. | + **Example** ```ts @@ -262,6 +369,11 @@ linkedList.add(1); linkedList.add(2); linkedList.add(4); let result = linkedList.getIndexOf(2); +try { + linkedList.getIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeByIndex @@ -284,6 +396,15 @@ Removes an element at the specified position from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeByIndex method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -294,6 +415,16 @@ linkedList.add(5); linkedList.add(2); linkedList.add(4); let result = linkedList.removeByIndex(2); +try { + linkedList.removeByIndex.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + linkedList.removeByIndex(8); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeFirst @@ -310,16 +441,35 @@ Removes the first element from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeFirst method cannot be bound. | +| 10200010 | Container is empty. | + **Example** ```ts let linkedList = new LinkedList(); +try { + linkedList.removeFirst(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} linkedList.add(2); linkedList.add(4); linkedList.add(5); linkedList.add(2); linkedList.add(4); let result = linkedList.removeFirst(); +try { + linkedList.removeFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeLast @@ -336,16 +486,35 @@ Removes the last element from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeLast method cannot be bound. | +| 10200010 | Container is empty. | + **Example** ```ts let linkedList = new LinkedList(); +try { + linkedList.removeLast(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} linkedList.add(2); linkedList.add(4); linkedList.add(5); linkedList.add(2); linkedList.add(4); let result = linkedList.removeLast(); +try { + linkedList.removeLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### remove @@ -368,6 +537,14 @@ Removes the first occurrence of the specified element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -377,6 +554,11 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.remove(2); +try { + linkedList.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeFirstFound @@ -399,15 +581,34 @@ Removes the first occurrence of the specified element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeFirstFound method cannot be bound. | +| 10200010 | Container is empty. | + **Example** ```ts let linkedList = new LinkedList(); +try { + linkedList.removeFirstFound(4); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} linkedList.add(2); linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.removeFirstFound(4); +try { + linkedList.removeFirstFound.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeLastFound @@ -430,15 +631,34 @@ Removes the last occurrence of the specified element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeLastFound method cannot be bound. | +| 10200010 | Container is empty. | + **Example** ```ts let linkedList = new LinkedList(); +try { + linkedList.removeLastFound(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} linkedList.add(2); linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.removeLastFound(4); +try { + linkedList.removeLastFound.bind({}, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### clone @@ -455,6 +675,14 @@ Clones this container and returns a copy. The modification to the copy does not | -------- | -------- | | LinkedList<T> | New **LinkedList** instance obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clone method cannot be bound. | + **Example** ```ts @@ -464,6 +692,11 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.clone(); +try { + linkedList.clone.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### forEach @@ -490,6 +723,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | LinkedList | LinkedList<T> | No| Instance that invokes the **forEach** API.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -501,6 +742,13 @@ linkedList.add(4); linkedList.forEach((value, index) => { console.log("value:" + value, index); }); +try { + linkedList.forEach.bind({}, (value, index) => { + console.log("value:" + value, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### clear @@ -511,6 +759,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -520,6 +776,11 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); linkedList.clear(); +try { + linkedList.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### set @@ -543,6 +804,15 @@ Replaces an element at the specified position in this container with a given ele | -------- | -------- | | T | New element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The set method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -552,6 +822,16 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.set(2, "b"); +try { + linkedList.set.bind({}, 2, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + linkedList.set(8, "b"); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### convertToArray @@ -568,6 +848,14 @@ Converts this container into an array. | -------- | -------- | | Array<T> | Array obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The convertToArray method cannot be bound. | + **Example** ```ts let linkedList = new LinkedList(); @@ -576,6 +864,11 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.convertToArray(); +try { + linkedList.convertToArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getFirst @@ -592,6 +885,14 @@ Obtains the first element in this container. | -------- | -------- | | T | Returns the element if obtained; returns **undefined** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getFirst method cannot be bound. | + **Example** ```ts @@ -601,6 +902,11 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); let result = linkedList.getFirst(); +try { + linkedList.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getLast @@ -617,6 +923,14 @@ Obtains the last element in this container. | -------- | -------- | | T | Returns the element if obtained; returns **undefined** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLast method cannot be bound. | + **Example** ```ts @@ -626,6 +940,11 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); linkedList.getLast(); +try { + linkedList.getLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### [Symbol.iterator] @@ -642,6 +961,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -663,4 +990,9 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + linkedList[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-list.md b/en/application-dev/reference/apis/js-apis-list.md index 4534668591a447df0a1f36d4f8ca3866a3e31692..181febf4ebe037fe37ec061efe832bd4f9a387cd 100644 --- a/en/application-dev/reference/apis/js-apis-list.md +++ b/en/application-dev/reference/apis/js-apis-list.md @@ -26,7 +26,7 @@ import List from '@ohos.util.List'; **System capability**: SystemCapability.Utils.Lang -| Name| Type| Readable| Writable| Description| +| Name| Type | Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | length | number | Yes| No| Number of elements in a list (called container later).| @@ -39,11 +39,23 @@ A constructor used to create a **List** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The List's constructor cannot be directly invoked. | **Example** ```ts let list = new List(); +try { + let list2 = List(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -67,16 +79,30 @@ Adds an element at the end of this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts let list = new List(); -let result = list.add("a"); -let result1 = list.add(1); +let result1 = list.add("a"); +let result2 = list.add(1); let b = [1, 2, 3]; -list.add(b); +let result3 = list.add(b); let c = {name : "Dylon", age : "13"}; -let result3 = list.add(false); +let result4 = list.add(c); +let result5 = list.add(false); +try { + list.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### insert @@ -94,6 +120,15 @@ Inserts an element at the specified position in this container. | element | T | Yes| Target element.| | index | number | Yes| Index of the position where the element is to be inserted.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The insert method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -101,6 +136,16 @@ let list = new List(); list.insert("A", 0); list.insert(0, 1); list.insert(true, 2); +try { + list.insert.bind({}, "b", 3)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + list.insert("b", 6); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### has @@ -123,6 +168,14 @@ Checks whether this container has the specified element. | -------- | -------- | | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -130,6 +183,11 @@ let list = new List(); let result = list.has("squirrel"); list.add("squirrel"); let result1 = list.has("squirrel"); +try { + list.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### get @@ -152,6 +210,14 @@ Obtains the element at the specified position in this container. | -------- | -------- | | T | Element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The get method cannot be bound. | + **Example** ```ts @@ -164,6 +230,11 @@ list.add(1); list.add(2); list.add(4); let result = list.get(2); +try { + list.get.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getLastIndexOf @@ -186,6 +257,14 @@ Obtains the index of the last occurrence of the specified element in this contai | -------- | -------- | | number | Returns the index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLastIndexOf method cannot be bound. | + **Example** ```ts @@ -198,6 +277,11 @@ list.add(1); list.add(2); list.add(4); let result = list.getLastIndexOf(2); +try { + list.getLastIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getIndexOf @@ -220,6 +304,14 @@ Obtains the index of the first occurrence of the specified element in this conta | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOf method cannot be bound. | + **Example** ```ts @@ -233,6 +325,11 @@ list.add(2); list.add(4); list.getIndexOf(2); let result = list.getIndexOf(2); +try { + list.getIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### equal @@ -255,6 +352,14 @@ Compares whether a specified object is equal to this container. | -------- | -------- | | boolean | Returns **true** if the two are equal; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The equal method cannot be bound. | + **Example** ```ts @@ -270,6 +375,11 @@ obj1.add(5); list.equal(obj1); let obj2 = {name : "Dylon", age : "13"}; let result = list.equal(obj2); +try { + list.equal.bind({}, obj2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### removeByIndex @@ -292,6 +402,15 @@ Removes an element at the specified position from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeByIndex method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -302,6 +421,16 @@ list.add(5); list.add(2); list.add(4); let result = list.removeByIndex(2); +try { + list.removeByIndex.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + list.removeByIndex(8); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### remove @@ -324,6 +453,14 @@ Removes the first occurrence of the specified element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -333,6 +470,11 @@ list.add(4); list.add(5); list.add(4); let result = list.remove(2); +try { + list.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### replaceAllElements @@ -359,6 +501,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | list | List<T> | No| Instance that invokes the **replaceAllElements** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The replaceAllElements method cannot be bound. | + **Example** ```ts @@ -373,6 +523,13 @@ list.replaceAllElements((value: number, index: number) => { list.replaceAllElements((value: number, index: number) => { return value = value - 2; }); +try { + list.replaceAllElements.bind({}, (value: number, index: number) => { + return value = 2 * value; + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### forEach @@ -399,6 +556,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | List | List<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -410,6 +575,13 @@ list.add(4); list.forEach((value, index) => { console.log("value: " + value, index); }); +try { + list.forEach.bind({}, (value, index) => { + console.log("value: " + value, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -434,6 +606,14 @@ comparator | firstValue | T | Yes| Previous element.| | secondValue | T | Yes| Next element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The sort method cannot be bound. | + **Example** ```ts @@ -444,6 +624,11 @@ list.add(5); list.add(4); list.sort((a: number, b: number) => a - b); list.sort((a: number, b: number) => b - a); +try { + list.sort.bind({}, (a: number, b: number) => b - a)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getSubList @@ -467,6 +652,15 @@ Obtains elements within a range in this container, including the element at the | -------- | -------- | | List<T> | New **List** instance obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getSubList method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -478,6 +672,16 @@ list.add(4); let result = list.getSubList(2, 4); let result1 = list.getSubList(4, 3); let result2 = list.getSubList(2, 6); +try { + list.getSubList.bind({}, 2, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + list.getSubList(2, 10); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### clear @@ -488,6 +692,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -497,6 +709,11 @@ list.add(4); list.add(5); list.add(4); list.clear(); +try { + list.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### set @@ -520,6 +737,15 @@ Replaces an element at the specified position in this container with a given ele | -------- | -------- | | T | New element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The set method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -529,7 +755,16 @@ list.add(4); list.add(5); list.add(4); list.set(2, "b"); - +try { + list.set.bind({}, 3, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + list.set(8, "b"); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### convertToArray @@ -546,6 +781,14 @@ Converts this container into an array. | -------- | -------- | | Array<T> | Array obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The convertToArray method cannot be bound. | + **Example** ```ts @@ -555,6 +798,11 @@ list.add(4); list.add(5); list.add(4); let result = list.convertToArray(); +try { + list.convertToArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### isEmpty @@ -571,6 +819,14 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts @@ -580,6 +836,11 @@ list.add(4); list.add(5); list.add(4); let result = list.isEmpty(); +try { + list.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getFirst @@ -596,6 +857,14 @@ Obtains the first element in this container. | -------- | -------- | | T | The first element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getFirst method cannot be bound. | + **Example** ```ts @@ -605,6 +874,11 @@ list.add(4); list.add(5); list.add(4); let result = list.getFirst(); +try { + list.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getLast @@ -621,6 +895,14 @@ Obtains the last element in this container. | -------- | -------- | | T | The last element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLast method cannot be bound. | + **Example** ```ts @@ -630,6 +912,11 @@ list.add(4); list.add(5); list.add(4); let result = list.getLast(); +try { + list.getLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### [Symbol.iterator] @@ -646,6 +933,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -667,4 +962,9 @@ while(temp != undefined) { console.log("value: " + temp); temp = iter.next().value; } +try { + list[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-plainarray.md b/en/application-dev/reference/apis/js-apis-plainarray.md index 568a479679c9457babba38a8da53e9a082f74f40..79ede0ce7a1aac37d64fe0a848e4bb5948cd877b 100644 --- a/en/application-dev/reference/apis/js-apis-plainarray.md +++ b/en/application-dev/reference/apis/js-apis-plainarray.md @@ -6,7 +6,7 @@ **PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value. -**PlainArray** is based on generics and uses a lightweight structure. Keys in the array are searched using binary search, which map to values in other arrays. +**PlainArray** is based on generics and uses a lightweight structure. Keys in the array are searched using binary search and are mapped to values in other arrays. Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used to store KV pairs in the lightweight structure. However, the key type of **PlainArray** can only be **number**. @@ -42,10 +42,23 @@ A constructor used to create a **PlainArray** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The PlainArray's constructor cannot be directly invoked. | + **Example** ```ts let plainArray = new PlainArray(); +try { + let plainArray2 = PlainArray(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -63,11 +76,24 @@ Checks whether this container is empty. | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const plainArray = new PlainArray(); let result = plainArray.isEmpty(); +try { + plainArray.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -91,6 +117,14 @@ Checks whether this container contains the specified key. | -------- | -------- | | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -98,6 +132,11 @@ let plainArray = new PlainArray(); plainArray.has(1); plainArray.add(1, "squirrel"); let result1 = plainArray.has(1); +try { + plainArray.has.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -121,6 +160,14 @@ Obtains the value of the specified key in this container. | -------- | -------- | | T | Value of the key.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The get method cannot be bound. | + **Example** ```ts @@ -128,6 +175,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let result = plainArray.get(1); +try { + plainArray.get.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -151,6 +203,14 @@ Obtains the index of the first occurrence of an element with the specified key i | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOfKey method cannot be bound. | + **Example** ```ts @@ -158,6 +218,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let result = plainArray.getIndexOfKey(2); +try { + plainArray.getIndexOfKey.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -181,6 +246,14 @@ Obtains the index of the first occurrence of an element with the specified value | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getIndexOfValue method cannot be bound. | + **Example** ```ts @@ -188,6 +261,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let result = plainArray.getIndexOfValue("squirrel"); +try { + plainArray.getIndexOfValue.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -211,6 +289,14 @@ Obtains the key of the element at the specified position in this container. | -------- | -------- | | number | Returns the key of the element if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getKeyAt method cannot be bound. | + **Example** ```ts @@ -218,6 +304,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let result = plainArray.getKeyAt(1); +try { + plainArray.getKeyAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getValueAt @@ -240,14 +331,33 @@ Obtains the value of an element at the specified position in this container. | -------- | -------- | | T | Returns the value of the element if obtained; returns **undefined** otherwise.| + **Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getValueAt method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** - ```ts - let plainArray = new PlainArray(); - plainArray.add(1, "squirrel"); - plainArray.add(2, "sparrow"); - let result = plainArray.getKeyAt(1); - ``` +```ts +let plainArray = new PlainArray(); +plainArray.add(1, "squirrel"); +plainArray.add(2, "sparrow"); +let result = plainArray.getValueAt(1); +try { + plainArray.getValueAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + plainArray.getValueAt(10); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +``` ### clone @@ -263,6 +373,14 @@ Clones this container and returns a copy. The modification to the copy does not | -------- | -------- | | PlainArray<T> | New **PlainArray** instance obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clone method cannot be bound. | + **Example** ```ts @@ -270,6 +388,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let newPlainArray = plainArray.clone(); +try { + plainArray.clone.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -288,11 +411,24 @@ Adds an element to this container. | key | number | Yes| Key of the target element.| | value | T | Yes| Value of the target element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); +try { + plainArray.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -316,14 +452,26 @@ Removes an element with the specified key from this container. | -------- | -------- | | T | Value of the element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); -plainArray.remove(2); let result = plainArray.remove(2); +try { + plainArray.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -347,14 +495,26 @@ Removes an element at the specified position from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeAt method cannot be bound. | + **Example** ```ts let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); -plainArray.removeAt(1); let result = plainArray.removeAt(1); +try { + plainArray.removeAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -379,6 +539,15 @@ Removes elements in a specified range from this container. | -------- | -------- | | number | Number of elements removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The removeRangeFrom method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -386,6 +555,16 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let result = plainArray.removeRangeFrom(1, 3); +try { + plainArray.removeRangeFrom.bind({}, 1, 3)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + plainArray.removeRangeFrom(10, 3); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -404,6 +583,15 @@ Sets a value for an element at the specified position in this container. | index | number | Yes| Position index of the target element.| | value | T | Yes| Value of the target element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The setValueAt method cannot be bound. | +| 10200001 | The value of parameters are out of range. | + **Example** ```ts @@ -411,6 +599,16 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); plainArray.setValueAt(1, 3546); +try { + plainArray.setValueAt.bind({}, 1, 3546)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} +try { + plainArray.setValueAt(10, 3); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -428,6 +626,14 @@ Obtains a string that contains all elements in this container. | -------- | -------- | | String | String obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The toString method cannot be bound. | + **Example** ```ts @@ -435,6 +641,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); let result = plainArray.toString(); +try { + plainArray.toString.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -446,6 +657,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -453,6 +672,11 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); plainArray.clear(); +try { + plainArray.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -478,6 +702,14 @@ callbackfn | index | number | No| Key of the element that is currently traversed.| | PlainArray | PlainArray<T>| No| Instance that invokes the **forEach** API.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -487,6 +719,13 @@ plainArray.add(2, "sparrow"); plainArray.forEach((value, index) => { console.log("value:" + value, index); }); +try { + plainArray.forEach.bind({}, (value, index) => { + console.log("value:" + value, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -504,6 +743,14 @@ Obtains an iterator object that contains key-value pairs, where the key is of th | -------- | -------- | | IterableIterator<[number, T]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -525,4 +772,9 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + plainArray[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-queue.md b/en/application-dev/reference/apis/js-apis-queue.md index 13ae6256d81a27c3fe53466ac175c74486051ee2..11ca91994e98310961e657db1a4c5e2554798c99 100644 --- a/en/application-dev/reference/apis/js-apis-queue.md +++ b/en/application-dev/reference/apis/js-apis-queue.md @@ -39,10 +39,23 @@ A constructor used to create a **Queue** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The Queue's constructor cannot be directly invoked. | + **Example** ```ts let queue = new Queue(); +try { + let queue2 = Queue(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -66,17 +79,29 @@ Adds an element at the end of this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts let queue = new Queue(); let result = queue.add("a"); let result1 = queue.add(1); -queue.add(1); let b = [1, 2, 3]; -queue.add(b); +let result2 = queue.add(b); let c = {name : "Dylon", age : "13"}; let result3 = queue.add(c); +try { + queue.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### pop @@ -93,6 +118,14 @@ Removes the first element from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The pop method cannot be bound. | + **Example** ```ts @@ -103,6 +136,11 @@ queue.add(5); queue.add(2); queue.add(4); let result = queue.pop(); +try { + queue.pop.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### getFirst @@ -119,6 +157,14 @@ Obtains the first element of this container. | -------- | -------- | | T | The first element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getFirst method cannot be bound. | + **Example** ```ts @@ -128,6 +174,11 @@ queue.add(4); queue.add(5); queue.add(2); let result = queue.getFirst(); +try { + queue.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### forEach @@ -154,6 +205,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | Queue | Queue<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -165,7 +224,13 @@ queue.add(4); queue.forEach((value, index) => { console.log("value:" + value, index); }); - +try { + queue.forEach.bind({}, (value, index) => { + console.log("value:" + value, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### [Symbol.iterator] @@ -182,8 +247,15 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| -**Example** +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + +**Example** ```ts let queue = new Queue(); queue.add(2); @@ -203,4 +275,9 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + queue[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-stack.md b/en/application-dev/reference/apis/js-apis-stack.md index a55afd6a634b5cb284741507140f9a35cf38a527..479550783c54d87accf6436cf6556e1b33a12ccc 100644 --- a/en/application-dev/reference/apis/js-apis-stack.md +++ b/en/application-dev/reference/apis/js-apis-stack.md @@ -41,10 +41,23 @@ A constructor used to create a **Stack** instance. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The Stack's constructor cannot be directly invoked. | + **Example** ```ts let stack = new Stack(); +try { + let stack2 = Stack(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -68,6 +81,14 @@ Adds an element at the top of this container. | -------- | -------- | | T | Element added.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The push method cannot be bound. | + **Example** ```ts @@ -75,9 +96,14 @@ let stack = new Stack(); let result = stack.push("a"); let result1 = stack.push(1); let b = [1, 2, 3]; -stack.push(b); +let result2 = stack.push(b); let c = {name : "Dylon", age : "13"}; let result3 = stack.push(c); +try { + stack.push.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### pop @@ -94,6 +120,14 @@ Removes the top element from this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The pop method cannot be bound. | + **Example** ```ts @@ -104,6 +138,11 @@ stack.push(5); stack.push(2); stack.push(4); let result = stack.pop(); +try { + stack.pop.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### peek @@ -120,6 +159,14 @@ Obtains the top element of this container. | -------- | -------- | | T | Element obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The peek method cannot be bound. | + **Example** ```ts @@ -129,6 +176,11 @@ stack.push(4); stack.push(5); stack.push(2); let result = stack.peek(); +try { + stack.peek.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### locate @@ -151,6 +203,14 @@ Obtains the index of the first occurrence of the specified element in this conta | -------- | -------- | | number | Returns the position index if obtained; returns **-1** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The locate method cannot be bound. | + **Example** ```ts @@ -160,6 +220,11 @@ stack.push(4); stack.push(5); stack.push(2); let result = stack.locate(2); +try { + stack.locate.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### forEach @@ -186,6 +251,14 @@ callbackfn | index | number | No| Position index of the element that is currently traversed.| | stack | Stack<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -197,6 +270,13 @@ stack.push(4); stack.forEach((value, index) => { console.log("value:" + value, index); }); +try { + stack.forEach.bind({}, (value, index) => { + console.log("value:" + value, index); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### isEmpty @@ -213,6 +293,14 @@ Checks whether this container is empty (contains no elements). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts @@ -222,6 +310,11 @@ stack.push(4); stack.push(5); stack.push(4); let result = stack.isEmpty(); +try { + stack.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### [Symbol.iterator] @@ -238,6 +331,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts let stack = new Stack(); @@ -258,4 +359,9 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + stack[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-treemap.md b/en/application-dev/reference/apis/js-apis-treemap.md index 001b08610c59f25b384c9fc3ada4c74f152b9313..e2a41d26819c96d3ef4321bfaf9a0e9f058300c9 100644 --- a/en/application-dev/reference/apis/js-apis-treemap.md +++ b/en/application-dev/reference/apis/js-apis-treemap.md @@ -47,10 +47,23 @@ A constructor used to create a **TreeMap** instance. | -------- | -------- | -------- | -------- | | comparator | function | No| Custom comparator.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The TreeMap's constructor cannot be directly invoked. | + **Example** ```ts let treeMap = new TreeMap(); +try { + let treeMap2 = TreeMap(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -68,11 +81,24 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const treeMap = new TreeMap(); let result = treeMap.isEmpty(); +try { + treeMap.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -96,6 +122,14 @@ Checks whether this container has the specified key. | -------- | -------- | | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasKey method cannot be bound. | + **Example** ```ts @@ -103,6 +137,11 @@ let treeMap = new TreeMap(); let result = treeMap.hasKey("squirrel"); treeMap.set("squirrel", 123); let result1 = treeMap.hasKey("squirrel"); +try { + treeMap.hasKey.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -126,6 +165,14 @@ Checks whether this container has the specified value. | -------- | -------- | | boolean | Returns **true** if the specified value is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The hasValue method cannot be bound. | + **Example** ```ts @@ -133,6 +180,11 @@ let treeMap = new TreeMap(); let result = treeMap.hasValue(123); treeMap.set("squirrel", 123); let result1 = treeMap.hasValue(123); +try { + treeMap.hasValue.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -156,6 +208,14 @@ Obtains the value of the specified key in this container. | -------- | -------- | | V | Value of the key.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The get method cannot be bound. | + **Example** ```ts @@ -163,6 +223,11 @@ let treeMap = new TreeMap(); treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); let result = treeMap.get("sparrow"); +try { + treeMap.get.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -180,6 +245,14 @@ Obtains the first key in this container. | -------- | -------- | | K | Key obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getFirstKey method cannot be bound. | + **Example** ```ts @@ -187,6 +260,11 @@ let treeMap = new TreeMap(); treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); let result = treeMap.getFirstKey(); +try { + treeMap.getFirstKey.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -204,6 +282,14 @@ Obtains the last key in this container. | -------- | -------- | | K | Key obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLastKey method cannot be bound. | + **Example** ```ts @@ -211,6 +297,11 @@ let treeMap = new TreeMap(); treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); let result = treeMap.getLastKey(); +try { + treeMap.getLastKey.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -228,6 +319,14 @@ Adds all elements in a **TreeMap** instance to this container. | -------- | -------- | -------- | -------- | | map | TreeMap<K, V> | Yes| **TreeMap** instance whose elements are to be added to the current container.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The setAll method cannot be bound. | + **Example** ```ts @@ -236,6 +335,11 @@ treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); let map = new TreeMap(); treeMap.setAll(map); +try { + treeMap.setAll.bind({}, map)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -260,11 +364,24 @@ Adds an element to this container. | -------- | -------- | | Object | Container that contains the new element.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The set method cannot be bound. | + **Example** ```ts let treeMap = new TreeMap(); treeMap.set("squirrel", 123); +try { + treeMap.set.bind({}, "squirrel", 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -288,6 +405,14 @@ Removes the element with the specified key from this container. | -------- | -------- | | V | Value of the element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -295,6 +420,11 @@ let treeMap = new TreeMap(); treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); treeMap.remove("sparrow"); +try { + treeMap.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -318,6 +448,14 @@ Obtains the key that is placed in front of the input key in this container. | -------- | -------- | | K | Key obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLowerKey method cannot be bound. | + **Example** ```ts @@ -326,6 +464,11 @@ treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); treeMap.set("gander", 356); let result = treeMap.getLowerKey("sparrow"); +try { + treeMap.getLowerKey.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -349,6 +492,14 @@ Obtains the key that is placed next to the input key in this container. | -------- | -------- | | K | Key obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getHigherKey method cannot be bound. | + **Example** ```ts @@ -357,6 +508,11 @@ treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); treeMap.set("gander", 356); let result = treeMap.getHigherKey("sparrow"); +try { + treeMap.getHigherKey.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` ### replace @@ -380,12 +536,25 @@ Replaces an element in this container. | -------- | -------- | | boolean | Returns **true** if the element is replaced successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The replace method cannot be bound. | + **Example** ```ts let treeMap = new TreeMap(); treeMap.set("sparrow", 123); let result = treeMap.replace("sparrow", 357); +try { + treeMap.replace.bind({}, "sparrow", 357)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -397,6 +566,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -404,6 +581,11 @@ let treeMap = new TreeMap(); treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); treeMap.clear(); +try { + treeMap.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -421,6 +603,14 @@ Obtains an iterator that contains all the keys in this container. | -------- | -------- | | IterableIterator<K> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The keys method cannot be bound. | + **Example** ```ts @@ -432,7 +622,12 @@ let temp = iter.next().value; while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; -} +} +try { + treeMap.keys.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -450,6 +645,14 @@ Obtains an iterator that contains all the values in this container. | -------- | -------- | | IterableIterator<V> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The values method cannot be bound. | + **Example** ```ts @@ -462,6 +665,11 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + treeMap.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -487,6 +695,14 @@ callbackfn | key | K | No| Key of the element that is currently traversed.| | map | TreeMap<K, V> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -496,6 +712,13 @@ treeMap.set("gull", 357); treeMap.forEach((value, key) => { console.log("value:" + value, key); }); +try { + treeMap.forEach.bind({}, (value, key) => { + console.log("value:" + value, key); + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -513,6 +736,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<[K, V]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The entries method cannot be bound. | + **Example** ```ts @@ -526,6 +757,11 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + treeMap.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -542,6 +778,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<[K, V]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -563,4 +807,9 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + treeMap[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-treeset.md b/en/application-dev/reference/apis/js-apis-treeset.md index 9391eb15c944bfa5170c28e4bd1976c346a3356a..ef10035349bf185462f803ad967270e79b8cc93d 100644 --- a/en/application-dev/reference/apis/js-apis-treeset.md +++ b/en/application-dev/reference/apis/js-apis-treeset.md @@ -44,10 +44,23 @@ A constructor used to create a **TreeSet** instance. | -------- | -------- | -------- | -------- | | comparator | function | No| Custom comparator.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200012 | The TreeSet's constructor cannot be directly invoked. | + **Example** ```ts let treeSet = new TreeSet(); +try { + let treeSet2 = TreeSet(); +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -65,11 +78,24 @@ Checks whether this container is empty (contains no element). | -------- | -------- | | boolean | Returns **true** if the container is empty; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The isEmpty method cannot be bound. | + **Example** ```ts const treeSet = new TreeSet(); let result = treeSet.isEmpty(); +try { + treeSet.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -93,6 +119,14 @@ Checks whether this container has the specified value. | -------- | -------- | | boolean | Returns **true** if the specified value is contained; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The has method cannot be bound. | + **Example** ```ts @@ -100,6 +134,11 @@ let treeSet = new TreeSet(); treeSet.has(123); treeSet.add(123); let result1 = treeSet.has(123); +try { + treeSet.has.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -117,6 +156,14 @@ Obtains the value of the first element in this container. | -------- | -------- | | T | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getFirstValue method cannot be bound. | + **Example** ```ts @@ -124,6 +171,11 @@ let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.add("sparrow"); let result = treeSet.getFirstValue(); +try { + treeSet.getFirstValue.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -141,6 +193,14 @@ Obtains the value of the last element in this container. | -------- | -------- | | T | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLastValue method cannot be bound. | + **Example** ```ts @@ -148,6 +208,11 @@ let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.add("sparrow"); let result = treeSet.getLastValue(); +try { + treeSet.getLastValue.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -171,11 +236,24 @@ Adds an element to this container. | -------- | -------- | | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The add method cannot be bound. | + **Example** ```ts let treeSet = new TreeSet(); let result = treeSet.add("squirrel"); +try { + treeSet.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -199,6 +277,14 @@ Removes the element with the specified key from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The remove method cannot be bound. | + **Example** ```ts @@ -206,6 +292,11 @@ let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.add("sparrow"); let result = treeSet.remove("sparrow"); +try { + treeSet.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -229,6 +320,14 @@ Obtains the value that is placed in front of the input key in this container. | -------- | -------- | | T | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getLowerValue method cannot be bound. | + **Example** ```ts @@ -237,6 +336,11 @@ treeSet.add("squirrel"); treeSet.add("sparrow"); treeSet.add("gander"); let result = treeSet.getLowerValue("sparrow"); +try { + treeSet.getLowerValue.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -260,6 +364,14 @@ Obtains the value that is placed next to the input key in this container. | -------- | -------- | | T | Value obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The getHigherValue method cannot be bound. | + **Example** ```ts @@ -268,6 +380,11 @@ treeSet.add("squirrel"); treeSet.add("sparrow"); treeSet.add("gander"); let result = treeSet.getHigherValue("sparrow"); +try { + treeSet.getHigherValue.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -285,6 +402,14 @@ Removes the first element in this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The popFirst method cannot be bound. | + **Example** ```ts @@ -292,6 +417,11 @@ let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.add("sparrow"); let result = treeSet.popFirst(); +try { + treeSet.popFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -309,6 +439,14 @@ Removes the last element in this container. | -------- | -------- | | T | Element removed.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The popLast method cannot be bound. | + **Example** ```ts @@ -316,6 +454,11 @@ let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.add("sparrow"); let result = treeSet.popLast(); +try { + treeSet.popLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -327,6 +470,14 @@ Clears this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The clear method cannot be bound. | + **Example** ```ts @@ -334,6 +485,11 @@ let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.add("sparrow"); treeSet.clear(); +try { + treeSet.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -351,6 +507,14 @@ Obtains an iterator that contains all the values in this container. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The values method cannot be bound. | + **Example** ```ts @@ -362,7 +526,12 @@ let temp = iter.next().value; while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; -} +} +try { + treeSet.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -388,6 +557,14 @@ callbackfn | key | T | No| Key of the element that is currently traversed (same as **value**).| | set | TreeSet<T> | No| Instance that invokes the **forEach** method.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The forEach method cannot be bound. | + **Example** ```ts @@ -397,6 +574,13 @@ treeSet.add("gull"); treeSet.forEach((value, key) => { console.log("value:" + value, key) }); +try { + treeSet.forEach.bind({}, (value, key) => { + console.log("value:" + value, key) + })(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -414,6 +598,14 @@ Obtains an iterator that contains all the elements in this container. | -------- | -------- | | IterableIterator<[T, T]> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The entries method cannot be bound. | + **Example** ```ts @@ -427,6 +619,11 @@ while(temp != undefined) { console.log("value:" + temp[1]); temp = iter.next().value; } +try { + treeSet.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` @@ -444,6 +641,14 @@ Obtains an iterator, each item of which is a JavaScript object. | -------- | -------- | | IterableIterator<T> | Iterator obtained.| +**Error codes** + +For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). + +| ID| Error Message| +| -------- | -------- | +| 10200011 | The Symbol.iterator method cannot be bound. | + **Example** ```ts @@ -463,4 +668,9 @@ while(temp != undefined) { console.log("value:" + temp); temp = iter.next().value; } +try { + treeSet[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture. +} catch(err) { + console.log(`${err.code} - ${err.name} - ${err.message}`); +} ``` diff --git a/en/application-dev/reference/apis/js-apis-vector.md b/en/application-dev/reference/apis/js-apis-vector.md index 24fc9e14ffe48ebbfd672aa73218c2110757c3d8..57b38f31c7e609fb59e1ff5266713e59d588c247 100644 --- a/en/application-dev/reference/apis/js-apis-vector.md +++ b/en/application-dev/reference/apis/js-apis-vector.md @@ -73,7 +73,7 @@ let vector = new Vector(); let result = vector.add("a"); let result1 = vector.add(1); let b = [1, 2, 3]; -vector.add(b); +let result2 = vector.add(b); let c = {name : "Dylon", age : "13"}; let result3 = vector.add(c); ``` @@ -286,8 +286,6 @@ vector.add(4); vector.add(5); vector.add(4); vector.removeByRange(2,4); -vector.removeByRange(4,3); -vector.removeByRange(2,6); ``` ### replaceAllElements @@ -431,9 +429,10 @@ vector.add(2); vector.add(4); vector.add(5); vector.add(4); -let result = vector.subVector(2,4); -let result1 = vector.subVector(4,3); -let result2 = vector.subVector(2,6); +vector.add(6); +vector.add(8); +let result = vector.subVector(0,4); +let result1 = vector.subVector(2,4); ``` diff --git a/en/application-dev/reference/errorcodes/errorcode-containers.md b/en/application-dev/reference/errorcodes/errorcode-containers.md new file mode 100644 index 0000000000000000000000000000000000000000..cc7c90db87480f8d74bd359248b62bc0844565f2 --- /dev/null +++ b/en/application-dev/reference/errorcodes/errorcode-containers.md @@ -0,0 +1,74 @@ +# containers Error Codes + +## 10200012 Constructor Calling Failure + +**Error Message** + +The {className}'s constructor cannot be directly invoked. + +**Description** + +A constructor of the **containers** class is called directly to create an instance. + +**Possible Causes** + +The constructors of the **containers** class cannot be directly called. The keyword **new** must be used. + +**Solution** + +Use the keyword **new** to create an instance. + +## 10200011 Passed this object Is Not an Instance of the containers Class + +**Error Message** + +The {methodName} method cannot be bound. + +**Description** + +**this object** passed in the API is not an instance of the **containers** class. + +**Possible Causes** + +The APIs of the **containers** class do not support **bind()**. + +**Solution** + +1. Check whether **bind()** is used to call the API. +2. Check whether an object that is not a container instance is assigned to the API. + +## 10200001 Invalid Parameter Value + +**Error Message** + +The value of parameters are out of range. + +**Description** + +The value of a parameter passed in the API exceeds the valid range. + +**Possible Causes** + +The parameter value is out of range. + +**Solution** + +Use a value within the range. + +## 10200010 Empty Container + +**Error Message** + +Container is empty. + +**Description** + +The container to be operated is empty. + +**Possible Causes** + +The container is empty. + +**Solution** + +Add elements to the container first.