未验证 提交 8c721ae6 编写于 作者: O openharmony_ci 提交者: Gitee

!5702 Modify the sample code of the language compilation runtime, which is...

!5702 Modify the sample code of the language compilation runtime, which is convenient for development and can be used in dev
Merge pull request !5702 from 李兴阳/master
...@@ -30,11 +30,11 @@ Creates a **URLSearchParams** instance. ...@@ -30,11 +30,11 @@ Creates a **URLSearchParams** instance.
**Example** **Example**
```js ```js
var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2}); var objectParams1 = new Url.URLSearchParams({"fod" : 1 , "bard" : 2});
var objectParams2 = new URLSearchParams('?fod=1&bard=2'); var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2');
var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2'); var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2');
var params = new URLSearchParams(urlObject.search); var params = new Url.URLSearchParams(urlObject.search);
``` ```
...@@ -56,8 +56,8 @@ Appends a key-value pair into the query string. ...@@ -56,8 +56,8 @@ Appends a key-value pair into the query string.
**Example** **Example**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', 3); paramsObject.append('fod', 3);
``` ```
...@@ -79,8 +79,8 @@ Deletes key-value pairs of the specified key. ...@@ -79,8 +79,8 @@ Deletes key-value pairs of the specified key.
**Example** **Example**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new URLSearchParams(urlObject.search.slice(1)); let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsobject.delete('fod'); paramsobject.delete('fod');
``` ```
...@@ -108,8 +108,8 @@ Obtains all the key-value pairs based on the specified key. ...@@ -108,8 +108,8 @@ Obtains all the key-value pairs based on the specified key.
**Example** **Example**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', 3); // Add a second value for the fod parameter. paramsObject.append('fod', 3); // Add a second value for the fod parameter.
console.log(params.getAll('fod')) // Output ["1","3"]. console.log(params.getAll('fod')) // Output ["1","3"].
``` ```
...@@ -132,7 +132,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ...@@ -132,7 +132,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
**Example** **Example**
```js ```js
var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2"); var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]); console.log(pair[0]+ ', '+ pair[1]);
} }
...@@ -165,7 +165,7 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal ...@@ -165,7 +165,7 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal
**Example** **Example**
```js ```js
const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); const myURLObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.searchParams.forEach((value, name, searchParams) => { myURLObject.searchParams.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams); console.log(name, value, myURLObject.searchParams === searchParams);
}); });
...@@ -196,7 +196,7 @@ Obtains the value of the first key-value pair based on the specified key. ...@@ -196,7 +196,7 @@ Obtains the value of the first key-value pair based on the specified key.
**Example** **Example**
```js ```js
var paramsOject = new URLSearchParams(document.location.search.substring(1)); var paramsOject = new Url.URLSearchParams(document.location.search.substring(1));
var name = paramsOject.get("name"); // is the string "Jonathan" var name = paramsOject.get("name"); // is the string "Jonathan"
var age = parseInt(paramsOject.get("age"), 10); // is the number 18 var age = parseInt(paramsOject.get("age"), 10); // is the number 18
var address = paramsOject.get("address"); // null var address = paramsOject.get("address"); // null
...@@ -226,8 +226,8 @@ Checks whether a key has a value. ...@@ -226,8 +226,8 @@ Checks whether a key has a value.
**Example** **Example**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.has('bard') === true; paramsObject.has('bard') === true;
``` ```
...@@ -250,8 +250,8 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t ...@@ -250,8 +250,8 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t
**Example** **Example**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.set('baz', 3); // Add a third parameter. paramsObject.set('baz', 3); // Add a third parameter.
``` ```
...@@ -267,7 +267,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi ...@@ -267,7 +267,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi
**Example** **Example**
```js ```js
var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs searchParamsObject.sort(); // Sort the key/value pairs
console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4
``` ```
...@@ -290,7 +290,7 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs. ...@@ -290,7 +290,7 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs.
**Example** **Example**
```js ```js
var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs for (var key of searchParamsObject .keys()) { // Output key-value pairs
console.log(key); console.log(key);
} }
...@@ -314,7 +314,7 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs. ...@@ -314,7 +314,7 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs.
**Example** **Example**
```js ```js
var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) { for (var value of searchParams.values()) {
console.log(value); console.log(value);
} }
...@@ -338,7 +338,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ...@@ -338,7 +338,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
**Example** **Example**
```js ```js
const paramsObject = new URLSearchParams('fod=bay&edg=bap'); const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) { for (const [name, value] of paramsObject) {
console.log(name, value); console.log(name, value);
} }
...@@ -362,8 +362,8 @@ Obtains search parameters that are serialized as a string and, if necessary, per ...@@ -362,8 +362,8 @@ Obtains search parameters that are serialized as a string and, if necessary, per
**Example** **Example**
```js ```js
let url = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new URLSearchParams(url.search.slice(1)); let params = new Url.URLSearchParams(url.search.slice(1));
params.append('fod', 3); params.append('fod', 3);
console.log(params.toString()); console.log(params.toString());
``` ```
...@@ -410,17 +410,17 @@ Creates a URL. ...@@ -410,17 +410,17 @@ Creates a URL.
```js ```js
var mm = 'http://username:password@host:8080'; var mm = 'http://username:password@host:8080';
var a = new URL("/", mm); // Output 'http://username:password@host:8080/'; var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/';
var b = new URL(mm); // Output 'http://username:password@host:8080/'; var b = new Url.URL(mm); // Output 'http://username:password@host:8080/';
new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1';
var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1
new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL
new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ new Url.URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/
new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ new Url.URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/
``` ```
...@@ -441,7 +441,7 @@ Converts the parsed URL into a string. ...@@ -441,7 +441,7 @@ Converts the parsed URL into a string.
**Example** **Example**
```js ```js
const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString() url.toString()
``` ```
...@@ -462,6 +462,6 @@ Converts the parsed URL into a JSON string. ...@@ -462,6 +462,6 @@ Converts the parsed URL into a JSON string.
**Example** **Example**
```js ```js
const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON() url.toJSON()
``` ```
\ No newline at end of file
...@@ -208,9 +208,6 @@ Decodes the input content. ...@@ -208,9 +208,6 @@ Decodes the input content.
result[4] = 0x62; result[4] = 0x62;
result[5] = 0x63; result[5] = 0x63;
console.log("input num:"); console.log("input num:");
for(var j= 0; j < 6; j++) {
console.log(result[j]);
}
var retStr = textDecoder.decode( result , {stream: false}); var retStr = textDecoder.decode( result , {stream: false});
console.log("retStr = " + retStr); console.log("retStr = " + retStr);
``` ```
...@@ -262,6 +259,7 @@ Encodes the input content. ...@@ -262,6 +259,7 @@ Encodes the input content.
**Example** **Example**
```js ```js
var textEncoder = new util.TextEncoder(); var textEncoder = new util.TextEncoder();
var buffer = new ArrayBuffer(20);
var result = new Uint8Array(buffer); var result = new Uint8Array(buffer);
result = textEncoder.encode("\uD800¥¥"); result = textEncoder.encode("\uD800¥¥");
``` ```
......
...@@ -55,6 +55,8 @@ Sets an attribute. ...@@ -55,6 +55,8 @@ Sets an attribute.
**Example** **Example**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.setAttributes("importance", "high"); thatSer.setAttributes("importance", "high");
``` ```
...@@ -77,6 +79,8 @@ Adds an empty element. ...@@ -77,6 +79,8 @@ Adds an empty element.
**Example** **Example**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.addEmptyElement("b"); // => <b/> thatSer.addEmptyElement("b"); // => <b/>
``` ```
...@@ -93,6 +97,8 @@ Sets a declaration. ...@@ -93,6 +97,8 @@ Sets a declaration.
**Example** **Example**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>; thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>;
``` ```
...@@ -133,6 +139,8 @@ Writes the end tag of the element. ...@@ -133,6 +139,8 @@ Writes the end tag of the element.
**Example** **Example**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("table"); thatSer.startElement("table");
......
...@@ -30,11 +30,11 @@ URLSearchParams的构造函数。 ...@@ -30,11 +30,11 @@ URLSearchParams的构造函数。
**示例:** **示例:**
```js ```js
var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2}); var objectParams1 = new Url.URLSearchParams({"fod" : 1 , "bard" : 2});
var objectParams2 = new URLSearchParams('?fod=1&bard=2'); var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2');
var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2'); var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2');
var params = new URLSearchParams(urlObject.search); var params = new Url.URLSearchParams(urlObject.search);
``` ```
...@@ -56,8 +56,8 @@ append(name: string, value: string): void ...@@ -56,8 +56,8 @@ append(name: string, value: string): void
**示例:** **示例:**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', 3); paramsObject.append('fod', 3);
``` ```
...@@ -79,8 +79,8 @@ delete(name: string): void ...@@ -79,8 +79,8 @@ delete(name: string): void
**示例:** **示例:**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new URLSearchParams(urlObject.search.slice(1)); let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsobject.delete('fod'); paramsobject.delete('fod');
``` ```
...@@ -108,8 +108,8 @@ getAll(name: string): string[] ...@@ -108,8 +108,8 @@ getAll(name: string): string[]
**示例:** **示例:**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', 3); // Add a second value for the fod parameter. paramsObject.append('fod', 3); // Add a second value for the fod parameter.
console.log(params.getAll('fod')) // Output ["1","3"]. console.log(params.getAll('fod')) // Output ["1","3"].
``` ```
...@@ -132,7 +132,7 @@ entries(): IterableIterator<[string, string]> ...@@ -132,7 +132,7 @@ entries(): IterableIterator<[string, string]>
**示例:** **示例:**
```js ```js
var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2"); var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]); console.log(pair[0]+ ', '+ pair[1]);
} }
...@@ -165,7 +165,7 @@ forEach(callbackfn: (value: string, key: string, searchParams: this) => void, th ...@@ -165,7 +165,7 @@ forEach(callbackfn: (value: string, key: string, searchParams: this) => void, th
**示例:** **示例:**
```js ```js
const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); const myURLObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.searchParams.forEach((value, name, searchParams) => { myURLObject.searchParams.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams); console.log(name, value, myURLObject.searchParams === searchParams);
}); });
...@@ -196,7 +196,7 @@ get(name: string): string | null ...@@ -196,7 +196,7 @@ get(name: string): string | null
**示例:** **示例:**
```js ```js
var paramsOject = new URLSearchParams(document.location.search.substring(1)); var paramsOject = new Url.URLSearchParams(document.location.search.substring(1));
var name = paramsOject.get("name"); // is the string "Jonathan" var name = paramsOject.get("name"); // is the string "Jonathan"
var age = parseInt(paramsOject.get("age"), 10); // is the number 18 var age = parseInt(paramsOject.get("age"), 10); // is the number 18
var address = paramsOject.get("address"); // null var address = paramsOject.get("address"); // null
...@@ -226,8 +226,8 @@ has(name: string): boolean ...@@ -226,8 +226,8 @@ has(name: string): boolean
**示例:** **示例:**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.has('bard') === true; paramsObject.has('bard') === true;
``` ```
...@@ -250,8 +250,8 @@ set(name: string, value: string): void ...@@ -250,8 +250,8 @@ set(name: string, value: string): void
**示例:** **示例:**
```js ```js
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.set('baz', 3); // Add a third parameter. paramsObject.set('baz', 3); // Add a third parameter.
``` ```
...@@ -267,7 +267,7 @@ sort(): void ...@@ -267,7 +267,7 @@ sort(): void
**示例:** **示例:**
```js ```js
var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs searchParamsObject.sort(); // Sort the key/value pairs
console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4
``` ```
...@@ -290,7 +290,7 @@ keys(): IterableIterator&lt;string&gt; ...@@ -290,7 +290,7 @@ keys(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```js
var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs for (var key of searchParamsObject .keys()) { // Output key-value pairs
console.log(key); console.log(key);
} }
...@@ -314,7 +314,7 @@ values(): IterableIterator&lt;string&gt; ...@@ -314,7 +314,7 @@ values(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```js
var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) { for (var value of searchParams.values()) {
console.log(value); console.log(value);
} }
...@@ -338,7 +338,7 @@ for (var value of searchParams.values()) { ...@@ -338,7 +338,7 @@ for (var value of searchParams.values()) {
**示例:** **示例:**
```js ```js
const paramsObject = new URLSearchParams('fod=bay&edg=bap'); const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) { for (const [name, value] of paramsObject) {
console.log(name, value); console.log(name, value);
} }
...@@ -362,8 +362,8 @@ toString(): string ...@@ -362,8 +362,8 @@ toString(): string
**示例:** **示例:**
```js ```js
let url = new URL('https://developer.exampleUrl/?fod=1&bard=2'); let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new URLSearchParams(url.search.slice(1)); let params = new Url.URLSearchParams(url.search.slice(1));
params.append('fod', 3); params.append('fod', 3);
console.log(params.toString()); console.log(params.toString());
``` ```
...@@ -410,17 +410,17 @@ URL的构造函数。 ...@@ -410,17 +410,17 @@ URL的构造函数。
```js ```js
var mm = 'http://username:password@host:8080'; var mm = 'http://username:password@host:8080';
var a = new URL("/", mm); // Output 'http://username:password@host:8080/'; var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/';
var b = new URL(mm); // Output 'http://username:password@host:8080/'; var b = new Url.URL(mm); // Output 'http://username:password@host:8080/';
new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1';
var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1
new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL
new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ new Url.URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/
new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ new Url.URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/
``` ```
...@@ -441,7 +441,7 @@ toString(): string ...@@ -441,7 +441,7 @@ toString(): string
**示例:** **示例:**
```js ```js
const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString() url.toString()
``` ```
...@@ -462,6 +462,6 @@ toJSON(): string ...@@ -462,6 +462,6 @@ toJSON(): string
**示例:** **示例:**
```js ```js
const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON() url.toJSON()
``` ```
...@@ -208,9 +208,6 @@ decode(input: Uint8Array, options?: { stream?: false }): string ...@@ -208,9 +208,6 @@ decode(input: Uint8Array, options?: { stream?: false }): string
result[4] = 0x62; result[4] = 0x62;
result[5] = 0x63; result[5] = 0x63;
console.log("input num:"); console.log("input num:");
for(var j= 0; j < 6; j++) {
console.log(result[j]);
}
var retStr = textDecoder.decode( result , {stream: false}); var retStr = textDecoder.decode( result , {stream: false});
console.log("retStr = " + retStr); console.log("retStr = " + retStr);
``` ```
...@@ -262,6 +259,7 @@ encode(input?: string): Uint8Array ...@@ -262,6 +259,7 @@ encode(input?: string): Uint8Array
**示例:** **示例:**
```js ```js
var textEncoder = new util.TextEncoder(); var textEncoder = new util.TextEncoder();
var buffer = new ArrayBuffer(20);
var result = new Uint8Array(buffer); var result = new Uint8Array(buffer);
result = textEncoder.encode("\uD800¥¥"); result = textEncoder.encode("\uD800¥¥");
``` ```
......
...@@ -55,6 +55,8 @@ setAttributes(name: string, value: string): void ...@@ -55,6 +55,8 @@ setAttributes(name: string, value: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.setAttributes("importance", "high"); thatSer.setAttributes("importance", "high");
``` ```
...@@ -77,6 +79,8 @@ addEmptyElement(name: string): void ...@@ -77,6 +79,8 @@ addEmptyElement(name: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.addEmptyElement("b"); // => <b/> thatSer.addEmptyElement("b"); // => <b/>
``` ```
...@@ -93,6 +97,8 @@ setDeclaration(): void ...@@ -93,6 +97,8 @@ setDeclaration(): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>; thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>;
``` ```
...@@ -133,6 +139,8 @@ endElement(): void ...@@ -133,6 +139,8 @@ endElement(): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); var thatSer = new xml.XmlSerializer(bufView);
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("table"); thatSer.startElement("table");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册