Keep prototype
var prototypeEmployed = {
toString: function () {
return "Name:" + this.name + ", Salary:" + this.salary;
}
};
function newEmployed(name, salary) {
var employed = Object.create(prototypeEmployed);
employed.name = name;
employed.salary = salary;
return employed;
}
prototypeEmployed.getCategory = function () {
return this.salary > 800 ? "Superior" : "Normal";
}
var joe= newEmployed("Jose", "10");
console.log("Joe ",joe.getCategory());
var walter= newEmployed("Walter", "100000");
console.log("Walter ",walter.getCategory());