30 Days Of JavaScript

Day 12: Classes

Lesson 4: Static

When we call const t = new Triangle(10, 10) we are calling the class constructor to give us a new Triangle instance.

When we call t.width we are accessing the width property of that specific instance of Triangle.

When we call t.area() we are calling the area() method of that specific instance of Triangle.

So the constructor is called on the class and the others are called on the instance. We area able to add other functionality to the class with the word static. For example we might want to ask the triangle class some information about it's self.

And you can do the same with methods. For instance we could have a method to calculate the area differences between two triangles like this.

Outline

Go Pro?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co