سلام. در مورد نوع تعریف classها سوال داشتم
میتونیم به اینصورت با constructor function یک کلاسی تعریف کنیم:
function Person(name, age, height)
{
this.name = name;
this.age = age;
this.height = height;
this.sayHi = function(){
return `my Name is:${this.name}`;
}
}
و یا با کلمه کلیدی class:
class Person {
constructor(name, age, height) {
this.name = name;
this.age = age;
this.height = height;
this.sayHi = function () {
return `my Name is:${this.name}`;
};
}
}
کارایی که این دو class انجام میدن یکسانه.
تفاوتشون چیه دقیقا؟