Hello campers , I am confused about the difference between those constuctors , I know that classes are syntactical sugar but why it is using constructor word fro declaring parameteres what I know is that the constructor is a property existed in function constructor prototype wich shows that is it created by that function .
The constructor function is the function used to initialise the properties of the object. The constructor property is a reference to that function.
function MyClass(foo) {
this.foo = foo;
}
Or
class MyClass {
constructor(foo) {
this.foo = foo;
}
}
> const myNewClass = new MyClass('hello')
> myNewClass.foo
'hello'
> myNewClass.constructor
function MyClass(foo) { this.foo = foo }