mituri

[JS] Dziedziczenie

Mar 9th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. console.clear();
  2.  
  3. Object.prototype.parent = function (supClass) {
  4. tempObj = new supClass();
  5. for (property in tempObj) {
  6. this[property] = tempObj[property];
  7. }
  8. };
  9.  
  10. function Bazowa() {
  11.  
  12. this.value = 5;
  13.  
  14. this.metoda1 = function () {
  15. console.log("Bazowa::metoda1() " + this.value);
  16. }
  17.  
  18. this.metoda2 = function () {
  19. console.log("Bazowa::metoda2()");
  20. }
  21. }
  22.  
  23. function Pochodna() {
  24. this.parent(Bazowa);
  25.  
  26. this.metoda1 = function () {
  27. console.log("Pochodna::metoda1() " + this.value);
  28. }
  29. }
  30.  
  31. x = new Pochodna();
  32. y = new Bazowa();
  33. x.metoda1();
  34. y.metoda1();
Advertisement
Add Comment
Please, Sign In to add comment