Skip to content

Instantly share code, notes, and snippets.

@wzalazar
Created October 31, 2014 01:51
Show Gist options
  • Save wzalazar/2406c8fd73dd89431b14 to your computer and use it in GitHub Desktop.
Save wzalazar/2406c8fd73dd89431b14 to your computer and use it in GitHub Desktop.
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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment