Please login to start chat

ICT Solutions 22 Jun 2022, 08:03:15
Category : JavaScript Tutorials

Getter and Setter (JS Classes)

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<script>
class Car{
constructor(brand){
this.carname = brand;
}
get cnam(){
return this.carname;
}
set cnam(x){
this.carname = x;
}
}
const myCar = new Car["Tesla"];
document.getElementById("demo").innerHTML = myCar;
</script>
</body>
</html>

Comments:

No comment to show.

Available Services
Download Android Application