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