Class Constructor and Methods
<html><head>
<title> Class Contructor and Methods </title>
</head>
<body>
<script>
class Person
{
constructor(firstName, lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
greet()
{
console.log("Name is " +
this.firstName + " " +
this.lastName);
}
}
var david = new Person("David","Thompson");
david.greet();
</script>
</body>
</html>
<!-- After you open this HTML file, F12 to open Console to see the output -->
<!-- Shift + Control + K in Mozilla, Shift + Control + J in Chrome -->
<title> Class Contructor and Methods </title>
</head>
<body>
<script>
class Person
{
constructor(firstName, lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
greet()
{
console.log("Name is " +
this.firstName + " " +
this.lastName);
}
}
var david = new Person("David","Thompson");
david.greet();
</script>
</body>
</html>
<!-- After you open this HTML file, F12 to open Console to see the output -->
<!-- Shift + Control + K in Mozilla, Shift + Control + J in Chrome -->