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.
<h1>Hello World<h1>
classTriangle{
constructor(height, width){
this.height= height
this.width= width
}
area(){
return(this.height*this.width)/2;
}
static description ="Triangle's are three sided shapes that tesselate and can be symmetrical down the y-axis"
}
let tri =newTriangle(10,10);
console.log(tri.area());
console.log(Triangle.description);
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.
<h1>Hello World<h1>
classTriangle{
constructor(height, width){
this.height= height
this.width= width
}
area(){
return(this.height*this.width)/2;
}
static description ="Triangle's are three sided shapes that tessellate and can be symmetrical down the y-axis";