提交 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) {
resolve(res)
setTimeout(() => {
resolve(res)
}, 2000)
})
// #endif
// #ifndef APP-ANDROID
return res
// #endif
}
/**
* 导出一个异步方法
......@@ -100,7 +97,7 @@ export async function testAsyncParam3(id : number, name : string, opts : AsyncOp
export class Test {
id : number;
name : string;
name : string;
static type : string = "Test";
constructor(id : number, options : TestOptions) {
......@@ -122,21 +119,21 @@ export class Test {
const res = await testAsync(opts);
return res;
}
}
export class SetterTest {
private _nickName: string = '';
get nickName (): string {
console.log('get nickName');
return this._nickName;
}
set nickName (value: string) {
console.log('set nickName');
this._nickName = value;
}
}
export class SetterTest {
private _nickName: string = '';
get nickName (): string {
console.log('get nickName');
return this._nickName;
}
set nickName (value: string) {
console.log('set nickName');
this._nickName = value;
}
}
class RequestTaskImpl implements RequestTask {
......@@ -161,15 +158,15 @@ export function request(url : string) : RequestTask | null {
return new RequestTaskImpl(url)
}
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
// #ifdef UNI-APP-X
export function callKotlinMethodGetInfo():String {
return NativeCode.getPhoneInfo()
}
}
export function callJavaMethodGetInfo():String {
return new JavaUser("jack",12).name
}
}
import KeyEvent from 'android.view.KeyEvent';
import Configuration from 'android.content.res.Configuration';
......
......@@ -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 {
......@@ -344,7 +345,7 @@ export function testString() : Result {
return "cat"
})
console.log("b:", b)
// 包含一个捕获组的示例。注意,目前android仅支持最多五个捕获组
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 {
......@@ -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.
先完成此消息的编辑!
想要评论请 注册