JavaScript中的类是什么?
类
甲类是一类的功能,但代替使用关键字“功能”,关键字“类”用于启动它,并且属性是一个内部分配构造()方法。的构造()方法被调用每个类对象初始化的时间。
示例1
在下面的示例中,创建了一个名为“company”的类,并在Constructor()方法中分配了公司名称,并将结果显示在输出中。
<html>
<body>
<p id="class"></p>
<script>
class Company {
constructor(branch) {
this.name = branch;
}
}
myComp = new Company("Nhooo");
document.getElementById("class").innerHTML = myComp.name;
</script>
</body>
</html>输出结果
Nhooo
示例2
<html>
<body>
<script>
class Company {
constructor(branch) {
this.name = branch;
}
}
myComp = new Company("Rk enterprises");
document.write(myComp.name);
</script>
</body>
</html>输出结果
Rk enterprises
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短