const obj = {
_sayHi() {
console.log(`Hello, my name is ${this.name}!`);
},
};
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
if (this.age < 0 ) {
this.age = 0;
}
}
}
const obj = {
_sayHi() {
console.log(`Hello, my name is ${this.name}!`);
}
};
class Person {
constructor(name, age, methods) {
this.name = name;
this.age = age;
this.methods = methods;
if (this.age < 0) {
this.age = 0;
}
}
sayMyName() {
this.methods._sayHi.call(this);
}
}
new Person('Heisenberg', 52, obj);
function fromPrototype(proto) {
function F() {}
F.protoype = proto;
return F;
}
const obj = {
_sayHi() {
console.log(`Hello, my name is ${this.name}!`);
},
};
class Person extends fromPrototype(obj) {
constructor(name, age) {
this.name = name;
this.age = age;
if (this.age < 0 ) {
this.age = 0;
}
}
}