JS OOP: 13. Class constructor

by istiq20

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Class constructor</title>
  </head>
  <body>
    <script>

      class Person {
        constructor(name) {
          // kode apapun
          console.info(`Hello ${name}`);
        }
      }

      const eko = new Person("Eko"); // Hello Eko
      const budi = new Person("Budi"); // Hello Budi

    </script>
  </body>
</html>