From df0b84cd2af834cca871d49fb62288b5e9af14dd Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 23 Nov 2022 19:26:01 +0800 Subject: [PATCH] docs: update syntax-uts.md --- docs/tutorial/syntax-uts.md | 179 ++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/docs/tutorial/syntax-uts.md b/docs/tutorial/syntax-uts.md index 14b53d824..94dd46c35 100644 --- a/docs/tutorial/syntax-uts.md +++ b/docs/tutorial/syntax-uts.md @@ -1651,6 +1651,12 @@ new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds] 表示自 UNIX 纪元开始(1970 年 1 月 1 日 00:00:00 (UTC))到当前时间的毫秒数。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts // this example takes 2 seconds to run const start = Date.now() @@ -1669,10 +1675,22 @@ setTimeout(() => { 根据本地时间,返回一个指定的日期对象为一个月中的哪一日(从 1--31)。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getDay 根据本地时间,返回一个具体日期中一周的第几天,0 表示星期天。对于某个月中的第几天 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getFullYear 根据本地时间返回指定日期的年份。 @@ -1681,34 +1699,82 @@ setTimeout(() => { 根据本地时间,返回一个指定的日期对象的小时。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getMilliseconds 根据本地时间,返回一个指定的日期对象的毫秒数。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getMinutes 根据本地时间,返回一个指定的日期对象的分钟数。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getMonth 指定的日期对象的月份,为基于 0 的值(0 表示一年中的第一月)。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getSeconds 根据本地时间,返回一个指定的日期对象的秒数。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### getTime 返回一个时间的格林威治时间数值。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### setDate 根据本地时间来指定一个日期对象的天数。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### setFullYear 根据本地时间为一个日期对象设置年份。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + #### setHours 根据本地时间为一个日期对象设置小时数,返回从 1970-01-01 00:00:00 UTC 到更新后的 日期 对象实例所表示时间的毫秒数。 @@ -1733,6 +1799,11 @@ setTimeout(() => { 以一个表示从 1970-1-1 00:00:00 UTC 计时的毫秒数为来为 Date 对象设置时间。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| ### Error @@ -1864,6 +1935,12 @@ Number 对象是经过封装的能让你处理数字值的对象。 toFixed() 方法使用定点表示法来格式化一个数值。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts function financial(x: Number): String { return x.toFixed(2); @@ -1885,6 +1962,12 @@ Set 对象是值的集合,你可以按照插入的顺序迭代它的元素。S 返回 Set 对象中元素的个数。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const set1 = new Set(); @@ -1917,6 +2000,12 @@ set1.forEach((item)=>{ clear() 方法用来清空一个 Set 对象中的所有元素。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const set1 = new Set(); set1.add(1); @@ -1932,6 +2021,12 @@ console.log(set1.size); delete() 方法可以从一个 Set 对象中删除指定的元素。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const map1 = new Map(); map1.set('bar', 'foo'); @@ -1950,6 +2045,12 @@ forEach 方法会根据集合中元素的插入顺序,依次执行提供的回 has() 方法返回一个布尔值来指示对应的值 value 是否存在 Set 对象中。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ### String String 全局对象是一个用于字符串或一个字符序列的构造函数。 @@ -2039,6 +2140,12 @@ console.log(`The character code ${sentence.charCodeAt(index)} is equal to ${sent concat() 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts let hello = 'Hello, ' console.log(hello.concat('Kevin', '. Have a nice day.')) @@ -2049,6 +2156,12 @@ console.log(hello.concat('Kevin', '. Have a nice day.')) endsWith() 方法用来判断当前字符串是否是以另外一个给定的子字符串“结尾”的,根据判断结果返回 true 或 false。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const str1 = 'Cats are the best!'; console.log(str1.endsWith('best!')); @@ -2064,6 +2177,12 @@ console.log(str2.endsWith('question')); includes() 方法用于判断一个字符串是否包含在另一个字符串中,根据情况返回 true 或 false。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const str = 'To be, or not to be, that is the question.'; @@ -2077,6 +2196,12 @@ console.log(str.includes('TO BE')); // false indexOf() 方法返回调用它的 String 对象中第一次出现的指定值的索引,从 fromIndex 处进行搜索。如果未找到该值,则返回 -1。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; @@ -2094,6 +2219,12 @@ console.log(`The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(searchT padEnd() 方法会用一个字符串填充当前字符串(如果需要的话则重复填充),返回填充后达到指定长度的字符串。从当前字符串的末尾(右侧)开始填充。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const str1 = 'Breaded Mushrooms'; console.log(str1.padEnd(25, '.')); @@ -2106,6 +2237,12 @@ console.log(str2.padEnd(5)); padStart() 方法用另一个字符串填充当前字符串 (如果需要的话,会重复多次),以便产生的字符串达到给定的长度。从当前字符串的左侧开始填充。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const str1 = '5'; console.log(str1.padStart(2, '0')); @@ -2115,6 +2252,12 @@ console.log(str1.padStart(2, '0')); repeat() 构造并返回一个新字符串,该字符串包含被连接在一起的指定数量的字符串的副本。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts "abc".repeat(0) // "" "abc".repeat(1) // "abc" @@ -2126,6 +2269,12 @@ repeat() 构造并返回一个新字符串,该字符串包含被连接在一 replace() 方法返回一个由替换值(replacement)替换部分或所有的模式(pattern)匹配项后的新字符串。模式可以是一个字符串或者一个正则表达式,替换值可以是一个字符串或者一个每次匹配都要调用的回调函数。如果pattern是字符串,则仅替换第一个匹配项。原字符串不会改变。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?'; @@ -2140,6 +2289,12 @@ console.log(p.replace(regex, 'ferret')); search() 方法执行正则表达式和 String 对象之间的一个搜索匹配。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; // any character that is not a word character or whitespace @@ -2153,6 +2308,12 @@ console.log(paragraph[paragraph.search(regex)]); slice() 方法提取某个字符串的一部分,并返回一个新的字符串,且不会改动原字符串。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const str = 'The quick brown fox jumps over the lazy dog.'; console.log(str.slice(31)); @@ -2165,6 +2326,12 @@ console.log(str.slice(4, 19)); split() 方法使用指定的分隔符字符串将一个String对象分割成子字符串数组,以一个指定的分割字串来决定每个拆分的位置。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const str = 'The quick brown fox jumps over the lazy dog.'; @@ -2179,6 +2346,12 @@ console.log(chars[8]); toLowerCase() 会将调用该方法的字符串值转为小写形式,并返回。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts console.log('中文简体 zh-CN || zh-Hans'.toLowerCase()); // 中文简体 zh-cn || zh-hans @@ -2189,6 +2362,12 @@ console.log('中文简体 zh-CN || zh-Hans'.toLowerCase()); toUpperCase() 方法将调用该方法的字符串转为大写形式并返回(如果调用该方法的值不是字符串类型会被强制转换)。 +**平台差异说明** + +|Web|Kotlin|Swift| +|:-:|:-:|:-:| +|√|√|x| + ```ts const sentence = 'The quick brown fox jumps over the lazy dog.'; console.log(sentence.toUpperCase()); -- GitLab