fork download
  1. var Person = (function() {
  2. var privates = {}; //obiekt, w ktorym bedziemy trzymac prywatne zmienne wszystkich obiektow
  3.  
  4. var Person = function (name) {
  5. this.name = name; //publiczna wlasnosc
  6. this.key = Math.random();
  7. privates[this.key] = {
  8. salary: NaN
  9. };
  10. };
  11.  
  12. var throwIfNoPermission = function(that) {
  13. if (Object.getPrototypeOf(that) !== Person.prototype) {
  14. throw new TypeError();
  15. }
  16. };
  17.  
  18. Person.prototype.getSalary = function() {
  19. throwIfNoPermission(this);
  20. return privates[this.key].salary;
  21. };
  22.  
  23. Person.prototype.setSalary = function(salary) {
  24. throwIfNoPermission(this);
  25. privates[this.key].salary = salary;
  26. };
  27.  
  28. return Person;
  29. }());
Success #stdin #stdout 0.39s 381952KB
stdin
Standard input is empty
stdout
Standard output is empty