提交 3daea108 编写于 作者: lizhongyi_'s avatar lizhongyi_ 提交者: mahaifeng

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

上级 207157cd
......@@ -52,14 +52,11 @@ export function testSyncWithCallback(opts : AsyncOptions) : SyntaxResult {
async function testAwaitPromise(res : SyntaxResult) : Promise<SyntaxResult> {
// #ifdef APP-ANDROID
return await new Promise(function (resolve : (res : SyntaxResult) => void) {
setTimeout(() => {
resolve(res)
}, 2000)
})
// #endif
// #ifndef APP-ANDROID
return res
// #endif
}
/**
* 导出一个异步方法
......
......@@ -7,10 +7,10 @@ export function testString() : Result {
const x = "Mozilla";
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" */
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" */
// #END
......@@ -335,6 +335,7 @@ export function testString() : Result {
// #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 b = a.replace(RegExp("fox"), function (match : string, offset : number, string : string) : string {
......@@ -355,6 +356,8 @@ export function testString() : Result {
return "cat"
})
console.log("b1", b1)
// #endif
// #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
......@@ -374,10 +377,12 @@ export function testString() : Result {
// #TEST String.search
const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const regex = /[^\w\s]/g;
// #ifdef APP-ANDROID
console.log(paragraph.search(regex));
// expected output: 43
console.log(paragraph[paragraph.search(regex)]);
// expected output: "."
// #endif
// #END
expect(paragraph.search(regex)).toEqual(43);
......
......@@ -163,7 +163,7 @@ export function testUTSJSONObject() : Result {
}
}
//返回指定键对应的值,如果对象中不存在此键则返回 null。
let name : string = person.get('name') as string
let name : string = person["name"] as String
//get 方法可以简化为使用下标运算符 `[]` 访问
name = person['name'] as string
//增加或更新指定键对应的值。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册