function Person(name) {
if (!(this instanceof Person)) {
return new Person(name);
}
this.name = name;
}
Person.prototype.greet = function () {
return `Hi ${this.name}`;
};
function Widget(id) {
this.id = id;
return { id: id * 2 };
}
Widget.prototype.getId = function () {
return this.id;
};
const p1 = Person('Zed');
const p2 = new Person('Nova');
const w = new Widget(5);
console.log(p1.greet(), p2.greet(), w.id, w.getId); Post #3445
2.15K
CHALLENGE
- ❤ 3
- 👍 1