<html>
<body>
<h2>JavaScript Class Method</h2>
<p>Demonstration of how to add a method in a JavaScript Class.</p>
<p id="demo"></p>
<script>
class Car {
constructor(brand) {
this.carname = brand;
}
present() {
return "I have a " + this.carname;
}
}
mycar = new Car("Ford");
document.getElementById("demo").innerHTML = mycar.present();
</script>
</body>
<!-- Mirrored from www.w3schools.com/js/tryit.asp?filename=tryjs_classes_method by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 02:39:34 GMT -->
</html>