Надо так
let Person =function(name,age,gender){
this.name = name;
this.age = age;
this.gender = gender;
return this;
};
Person.prototype.greet= function(){
console.log("My name is " + this.name);
};
var tom = new Person("Вася",18,"female");
tom.greet();
Либо так
class Person {
constructor (name,age,gender){
this.name = name;
this.age = age;
this.gender = gender;
return this;
}
greet (){
console.log("My name is " + this.name);
}
}
var tom = new Person("Вася",18,"female");
tom.greet();
В крайнем случае (непонятно, зачем) так
let Person = {
constructor:function(name,age,gender){
this.name = name;
this.age = age;
this.gender = gender;
this.greet = Person.greet;
return this;
},
greet: function(){
console.log("My name is " + this.name);
}
};
var tom = new Person.constructor("Вася",18,"female");
tom.greet();