Javascript Class example Constructor and Methods

A "House" class is created with a constructor function that collects the width, height, and color of the house.

The "House" class has two methods:

  • The getArea method to retrieve the area of the house according to the height and width collected in the class.
  • The dimension method that returns the dimensions of the class according to the parameters entered for the particular method itself.

An object "house1" is created with its properties and the color property, the dimensions and the area of the house are displayed on the screen.

Comments

PHP Captcha


Interesting Articles