Hi, basic question: why is the constructor needed in class?
Below is a simple test:
- Circle class with a constructor function
- Circle2 class without a constructor function.
- … However, both classes work and an instance can be created.
Going back to the topic, why is the constructor needed in class?
//=================================
console.log ('//1 ----------- ES6 Classes ----------- ');
//=================================
class Circle{
draw(){console.log ('hello');}
}
c = new Circle(1);
class Circle2{
constructor(radius){
this.radius = radius;
}
draw(){console.log ('hello');}
}
c2 = new Circle2(1);