javascript - 如何从同一类创建 2 个不同的实例?
问题描述
如何在控制台中显示 Cat 类的两个实例:Skitty,9 年和 Pixel,6 年?
(() => {
class Cat {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
document.getElementById("run").addEventListener("click",() => {
// your code here
})
})();
在此先感谢,如果问题愚蠢,我很抱歉,我正在学习!
解决方案
const instance1 = new Cat('Skitty', 9);
const instance2 = new Cat('Pixel', 6);
console.log(instance1, instance2);
推荐阅读
- python - WebDriverWait until_not 和 Python 和 Selenium 上的不可见性太慢
- spring-boot - 设置多个 JPA 数据源时出现 NoUniqueBeanDefinitionException
- testing - 将长时间运行的测试作为 CI 的一部分包含在内的“良好实践”方法是什么?
- sql - 如何将事件和日期的 SQL Server 表查询到以事件为属性的列中以及不同列中的日期?
- java - 从 Hibernate 调用过程时出错
- javascript - 如何在不缓存 JavaScript/ReactJS 中的重定向的情况下重定向页面?
- pyspark - Python 在 pyspark.sql 中使用列表参数,就像 sas 中的宏一样
- huggingface-transformers - 如何为不同的输入而不是 [CLS] 令牌初始化 BertForSequenceClassification?
- reactjs - 在函数中创建时未在 React 中呈现的组件
- javascript - JavaScript 过滤器数组与另一个数组的过滤器