Created
October 31, 2014 01:51
-
-
Save wzalazar/2406c8fd73dd89431b14 to your computer and use it in GitHub Desktop.
Keep prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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