找回密码
 立即注册

微信登录

只需一步,快速开始

QQ登录

只需一步,快速开始

搜索
查看: 440|回复: 1

[教程] aardio实现封装继承多态

[复制链接]
  • TA的每日心情
    无聊
    2024-3-3 20:52
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    10

    主题

    5

    回帖

    116

    积分

    版主

    积分
    116
    来自: 亚太地区
    发表于 2024-2-8 00:05:55 | 显示全部楼层 |阅读模式 来自: 亚太地区
    非业余 - aardio 编程语言 - 非官方问答社区
    限时85折!暑假期间,用aardio培训班充实自己!https://mp.weixin.qq.com/s/c4Z8sZPOiMh_OTG2VPOJmA
    Aardio培训大揭秘,轻松上手打造个人项目!https://mp.weixin.qq.com/s/cr47qhp_Cpz0p57lbbPwug
    aardio风行者第二期培训班https://mp.weixin.qq.com/s/uB6XHUDnGSk0JlWuiBE9AA
    本帖最后由 axuanup 于 2024-2-8 00:19 编辑

    [AAuto] 纯文本查看 复制代码
    import console; 
    
    //封装
    class Animal{
        ctor(name) {
            this.name = name
        }
    
        eat = function() {
            ..console.log(this.name + " is eating.")
        }
    }
    
    //继承
    class Carnivore{
        ctor(name) {
            this = ..Animal(name)
        }
    
        eat = function() {
            ..console.log(this.name + " is eating meat.")
        }
    }
    
    //多态
    class Herbivore{
        ctor(name) {
            this = ..Animal(name)
        }
    
        eat = function() {
            ..console.log(this.name + " is eating plants.")
        }
    }
    
    var carnivore = Carnivore("Tiger")
    var herbivore = Herbivore("Deer")
    carnivore.eat()  // 输出 "Tiger is eating meat."
    herbivore.eat()  // 输出 "Deer is eating plants."
    
    console.pause(true);

    非业余 - aardio 编程语言 - 非官方问答社区
    限时85折!暑假期间,用aardio培训班充实自己!https://mp.weixin.qq.com/s/c4Z8sZPOiMh_OTG2VPOJmA
    Aardio培训大揭秘,轻松上手打造个人项目!https://mp.weixin.qq.com/s/cr47qhp_Cpz0p57lbbPwug
    aardio风行者第二期培训班https://mp.weixin.qq.com/s/uB6XHUDnGSk0JlWuiBE9AA
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-4-23 09:26
  • 签到天数: 6 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    0

    主题

    7

    回帖

    68

    积分

    注册会员

    积分
    68
    来自: 中国福建泉州
    发表于 2024-2-12 03:59:08 | 显示全部楼层 来自: 中国福建泉州
    支持了,学习下
    回复

    使用道具 举报

    *滑块验证:
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|非业余 - aardio 编程语言 - 非官方问答社区

    GMT+8, 2024-9-17 03:32 , Processed in 0.126421 second(s), 30 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表