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
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便