Funciones de constructor
Ejemplo:
function Employee(name) {
this.name = name;
}
Employee.prototype.salary = function () {
console.log(`Su salario es de $.12,000.00`);
};
function Salesperson(name) {
Employee.call(this, name);
}
function inherit(proto) {
function ChainLink() {}
ChainLink.prototype = proto;
return new ChainLink();
}
Salesperson.prototype = inherit(Employee.prototype);
Salesperson.prototype.sell = function () {
console.log(`Es vendido por ${this.name}`);
};
const smith = new Salesperson('Smith Peterson');
smith.sell(); // Es vendido por Smith Peterson
smith.salary(); // Su salario es de $.12,000.00
console.log(Object.getPrototypeOf(smith) === Salesperson.prototype); // true
console.log(Object.getPrototypeOf(Salesperson.prototype) === Employee.prototype); // trueLast updated