Guest User

Untitled

a guest
May 27th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. var Animal, Horse, Snake, sam, tom;
  2. var __extends = function(child, parent) {
  3. var ctor = function(){ };
  4. ctor.prototype = parent.prototype;
  5. child.__superClass__ = parent.prototype;
  6. child.prototype = new ctor();
  7. child.prototype.constructor = child;
  8. };
  9. Animal = function() {
  10. };
  11. Animal.prototype.move = function(meters) {
  12. return alert(this.name + " moved " + meters + "m.");
  13. };
  14. Animal.Mixin = function(self){
  15. var sex = "male";
  16.  
  17. self.getSex = function(){
  18. return sex;
  19. }
  20. }
  21.  
  22. Snake = function(name) {
  23. new Animal.Mixin(this);
  24. this.name = name;
  25. return this;
  26. };
  27. __extends(Snake, Animal);
  28. Snake.prototype.move = function() {
  29. alert("Slithering...");
  30. return Snake.__superClass__.move.call(this, 5);
  31. };
  32.  
  33. Python = function(name) {
  34. this.name = name;
  35. return this;
  36. };
  37. __extends(Python, Snake);
  38. Python.prototype.move = function() {
  39. alert("Pythonlithering...");
  40. return Python.__superClass__.move.call(this, 5);
  41. };
  42.  
  43. Horse = function(name) {
  44. this.name = name;
  45. return this;
  46. };
  47. __extends(Horse, Animal);
  48. Horse.prototype.move = function() {
  49. alert("Galloping...");
  50. return Horse.__superClass__.move.call(this, 45);
  51. };
  52.  
  53. sam = new Snake("Sammy the Python");
  54. tom = new Horse("Tommy the Palomino");
Add Comment
Please, Sign In to add comment