Javascript:如何从同一类创建两个不同的实例?

问题描述 投票:-1回答:1

我如何在控制台中显示Cat类的两个实例:9岁的Skitty和6岁的Pixel?

(() => {
    class Cat {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }
    }
    document.getElementById("run").addEventListener("click",() => {
    // your code here

    })

})();

谢谢,如果问题很愚蠢,我正在学习,抱歉!

javascript arrays object instance
1个回答
0
投票
const instance1 = new Cat('Skitty', 9);
const instance2 = new Cat('Pixel', 6);
© www.soinside.com 2019 - 2024. All rights reserved.