了解ArkTS语言

了解ArkTS语言

十二月 20, 2023 评论 10 阅读 525 点赞 0 收藏 0

数据对比

居中

定义变量

#自动 监听数据改变

Android Runtime Kit TypeScript

类型

函数

类和接口


// 定义枚举
enum Msg {
    HI = 'Hi',
    HELLO = 'Hello'
}
// 定义接口
interface A {
    say(msg:Msg):void
}
// 定义类,实现接口
class B implements A {
    say(msg:Msg):void{
        console.log(msg + ', I am B')
    }
}
// 初始化对象
let a:B = new B()
// 调用方法,传递枚举参数
a.say(Msg.HI)

// 定义规形类
class Rectangle {
    // 成员变量
    private width: number
    private length: number
    // 构造函数
    constructor(width:number,length:number){
        this.width = width
        this.length = length
    }
    // 成员方法
    public area():number{
        return this.width * this.length
    }
}
// 定义正方形
class Square extends Rectangle {
    constructor(side:number){
        // 调用父类
        super(side,side)
    }
}

let s = new Square(10)
console.log('正方形面积为:' + s.area())
"use strict";
// 定义规形类
class Rectangle {
    // 构造函数
    constructor(width, length) {
        this.width = width;
        this.length = length;
    }
    // 成员方法
    area() {
        return this.width * this.length;
    }
}
// 定义正方形
class Square extends Rectangle {
    constructor(side) {
        // 调用父类
        super(side, side);
    }
}
let s = new Square(10);
console.log('正方形面积为:' + s.area());

模块开发



第一个“hello world”

*
*
*