提交 4f39a3f7 编写于 作者: lizhongyi_'s avatar lizhongyi_

调整部分示例避免iOS编译报错

上级 16b9306d
...@@ -53,7 +53,7 @@ export function onCallback(callback: (sth:string) => void) { ...@@ -53,7 +53,7 @@ export function onCallback(callback: (sth:string) => void) {
let count = 1 let count = 1
let taskId = -1 let taskId = -1
taskId = setInterval(function() { taskId = setInterval(function() {
callback("第" + count + "次回调") callback(`第 ${count} 次回调`)
count++; count++;
console.log("count",count) console.log("count",count)
if(count > 3){ if(count > 3){
......
...@@ -440,7 +440,7 @@ export function Scan1(timeMillis ?: Number):string { ...@@ -440,7 +440,7 @@ export function Scan1(timeMillis ?: Number):string {
if(timeMillis == null){ if(timeMillis == null){
return "null" return "null"
} }
return timeMillis.toString() return timeMillis!.toString()
} }
export function Scan2(timeMillis ?: Number | null):string { export function Scan2(timeMillis ?: Number | null):string {
...@@ -448,7 +448,7 @@ export function Scan2(timeMillis ?: Number | null):string { ...@@ -448,7 +448,7 @@ export function Scan2(timeMillis ?: Number | null):string {
if(timeMillis == null){ if(timeMillis == null){
return "null" return "null"
} }
return timeMillis.toString() return timeMillis!.toString()
} }
export class myClass { export class myClass {
......
...@@ -112,8 +112,9 @@ export function testMath() : Result { ...@@ -112,8 +112,9 @@ export function testMath() : Result {
// #TEST Math.acos // #TEST Math.acos
console.log(Math.acos(-1)); console.log(Math.acos(-1));
// expected output: 3.141592653589793 // expected output: 3.141592653589793
// #ifdef APP-ANDROID
console.log(Math.acos(NaN)); console.log(Math.acos(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.acos(0)); console.log(Math.acos(0));
...@@ -133,8 +134,9 @@ export function testMath() : Result { ...@@ -133,8 +134,9 @@ export function testMath() : Result {
// #TEST Math.acosh // #TEST Math.acosh
console.log(Math.acosh(1)); console.log(Math.acosh(1));
// expected output: 0 // expected output: 0
// #ifdef APP-ANDROID
console.log(Math.acosh(NaN)); console.log(Math.acosh(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.acosh(2)); console.log(Math.acosh(2));
...@@ -152,7 +154,9 @@ export function testMath() : Result { ...@@ -152,7 +154,9 @@ export function testMath() : Result {
test('asin', () => { test('asin', () => {
// #TEST Math.asin // #TEST Math.asin
// #ifdef APP-ANDROID
console.log(Math.asin(NaN)); console.log(Math.asin(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.asin(-1)); console.log(Math.asin(-1));
...@@ -177,7 +181,9 @@ export function testMath() : Result { ...@@ -177,7 +181,9 @@ export function testMath() : Result {
test('asinh', () => { test('asinh', () => {
// #TEST Math.asinh // #TEST Math.asinh
// #ifdef APP-ANDROID
console.log(Math.asinh(NaN)); console.log(Math.asinh(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.asinh(1)); console.log(Math.asinh(1));
...@@ -202,7 +208,9 @@ export function testMath() : Result { ...@@ -202,7 +208,9 @@ export function testMath() : Result {
test('atan', () => { test('atan', () => {
// #TEST Math.atan // #TEST Math.atan
// #ifdef APP-ANDROID
console.log(Math.atan(NaN)); console.log(Math.atan(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.atan(1)); console.log(Math.atan(1));
...@@ -231,7 +239,9 @@ export function testMath() : Result { ...@@ -231,7 +239,9 @@ export function testMath() : Result {
test('atanh', () => { test('atanh', () => {
// #TEST Math.atanh // #TEST Math.atanh
// #ifdef APP-ANDROID
console.log(Math.atanh(NaN)); console.log(Math.atanh(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.atanh(0)); console.log(Math.atanh(0));
...@@ -253,8 +263,9 @@ export function testMath() : Result { ...@@ -253,8 +263,9 @@ export function testMath() : Result {
// #TEST Math.ceil // #TEST Math.ceil
console.log(Math.ceil(0.95)); console.log(Math.ceil(0.95));
// expected output: 1 // expected output: 1
// #ifdef APP-ANDROID
console.log(Math.ceil(NaN)); console.log(Math.ceil(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.ceil(4)); console.log(Math.ceil(4));
...@@ -383,7 +394,9 @@ export function testMath() : Result { ...@@ -383,7 +394,9 @@ export function testMath() : Result {
test('fround', () => { test('fround', () => {
// #TEST Math.fround // #TEST Math.fround
// #ifdef APP-ANDROID
console.log(Math.fround(NaN)); console.log(Math.fround(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.fround(1.5)); console.log(Math.fround(1.5));
...@@ -626,23 +639,28 @@ export function testMath() : Result { ...@@ -626,23 +639,28 @@ export function testMath() : Result {
test('round', () => { test('round', () => {
// #TEST Math.round // #TEST Math.round
// #ifdef APP-ANDROID
console.log(Math.round(NaN)); console.log(Math.round(NaN));
// #endif
// expected output: NaN // expected output: NaN
console.log(Math.round(Math.E)); console.log(Math.round(Math.E));
// expected output: 3 // expected output: 3
// #ifdef APP-ANDROID
console.log(Math.round(Number.MAX_VALUE)); console.log(Math.round(Number.MAX_VALUE));
// expected output: 1.7976931348623157e+308 // expected output: 1.7976931348623157e+308
console.log(Math.round(Number.MIN_VALUE)); console.log(Math.round(Number.MIN_VALUE));
// expected output: 0 // expected output: 0
console.log(Math.round(Number.NEGATIVE_INFINITY)); console.log(Math.round(Number.NEGATIVE_INFINITY));
// expected output: -Infinity // expected output: -Infinity
console.log(Math.round(Number.POSITIVE_INFINITY)); console.log(Math.round(Number.POSITIVE_INFINITY));
// expected output: Infinity // expected output: Infinity
// #endif
console.log(Math.round(0.9)); console.log(Math.round(0.9));
// expected output: 1 // expected output: 1
...@@ -661,10 +679,14 @@ export function testMath() : Result { ...@@ -661,10 +679,14 @@ export function testMath() : Result {
// #END // #END
expect(Math.round(NaN)).toEqual(NaN); expect(Math.round(NaN)).toEqual(NaN);
expect(Math.round(Math.E)).toEqual(3); expect(Math.round(Math.E)).toEqual(3);
// #ifdef APP-ANDROID
expectNumber(Math.round(Number.MAX_VALUE)).toEqualDouble(1.7976931348623157e+308); expectNumber(Math.round(Number.MAX_VALUE)).toEqualDouble(1.7976931348623157e+308);
expect(Math.round(Number.MIN_VALUE)).toEqual(0); expect(Math.round(Number.MIN_VALUE)).toEqual(0);
expect(Math.round(Number.NEGATIVE_INFINITY)).toEqual(-Infinity); expect(Math.round(Number.NEGATIVE_INFINITY)).toEqual(-Infinity);
expect(Math.round(Number.POSITIVE_INFINITY)).toEqual(Infinity); expect(Math.round(Number.POSITIVE_INFINITY)).toEqual(Infinity);
// #endif
expect(Math.round(0.9)).toEqual(1); expect(Math.round(0.9)).toEqual(1);
expect(Math.round(5.95)).toEqual(6); expect(Math.round(5.95)).toEqual(6);
expect(Math.round(-5.05)).toEqual(-5); expect(Math.round(-5.05)).toEqual(-5);
......
...@@ -7,10 +7,10 @@ export function testString() : Result { ...@@ -7,10 +7,10 @@ export function testString() : Result {
const x = "Mozilla"; const x = "Mozilla";
const e = ""; const e = "";
console.log("Mozilla is " + x.length + " code units long"); console.log("Mozilla is " + `${x.length}` + " code units long");
/* "Mozilla is 7 code units long" */ /* "Mozilla is 7 code units long" */
console.log("The empty string is has a length of " + e.length); console.log("The empty string is has a length of " + `${e.length}`);
/* "The e string is has a length of 0" */ /* "The e string is has a length of 0" */
// #END // #END
...@@ -335,6 +335,7 @@ export function testString() : Result { ...@@ -335,6 +335,7 @@ export function testString() : Result {
// #TEST String.replace_1 // #TEST String.replace_1
// #ifdef APP-ANDROID
// 不包含捕捉组的示例 // 不包含捕捉组的示例
let a = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?" let a = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?"
let b = a.replace(RegExp("fox"), function (match : string, offset : number, string : string) : string { let b = a.replace(RegExp("fox"), function (match : string, offset : number, string : string) : string {
...@@ -344,7 +345,7 @@ export function testString() : Result { ...@@ -344,7 +345,7 @@ export function testString() : Result {
return "cat" return "cat"
}) })
console.log("b:", b) console.log("b:", b)
// 包含一个捕获组的示例。注意,目前android仅支持最多五个捕获组 // 包含一个捕获组的示例。注意,目前android仅支持最多五个捕获组
let a1 = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?" let a1 = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?"
let b1 = a1.replace(RegExp("(fox)"), function (match : string, p1 : string, offset : number, string : string) : string { let b1 = a1.replace(RegExp("(fox)"), function (match : string, p1 : string, offset : number, string : string) : string {
...@@ -355,6 +356,8 @@ export function testString() : Result { ...@@ -355,6 +356,8 @@ export function testString() : Result {
return "cat" return "cat"
}) })
console.log("b1", b1) console.log("b1", b1)
// #endif
// #END // #END
// const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g // const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g
...@@ -374,10 +377,12 @@ export function testString() : Result { ...@@ -374,10 +377,12 @@ export function testString() : Result {
// #TEST String.search // #TEST String.search
const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const regex = /[^\w\s]/g; const regex = /[^\w\s]/g;
// #ifdef APP-ANDROID
console.log(paragraph.search(regex)); console.log(paragraph.search(regex));
// expected output: 43 // expected output: 43
console.log(paragraph[paragraph.search(regex)]); console.log(paragraph[paragraph.search(regex)]);
// expected output: "." // expected output: "."
// #endif
// #END // #END
expect(paragraph.search(regex)).toEqual(43); expect(paragraph.search(regex)).toEqual(43);
......
...@@ -170,7 +170,7 @@ export function testUTSJSONObject() : Result { ...@@ -170,7 +170,7 @@ export function testUTSJSONObject() : Result {
} }
} }
//返回指定键对应的值,如果对象中不存在此键则返回 null。 //返回指定键对应的值,如果对象中不存在此键则返回 null。
let name : string = person.get('name') as string let name : string = person["name"] as String
//get 方法可以简化为使用下标运算符 `[]` 访问 //get 方法可以简化为使用下标运算符 `[]` 访问
name = person['name'] as string name = person['name'] as string
//增加或更新指定键对应的值。 //增加或更新指定键对应的值。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册