Guest User

Untitled

a guest
May 27th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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 console.log(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. self.thinkThenMove = function(){
  22. console.log("thinking...");
  23. self.move();
  24. }
  25. }
  26.  
  27. Snake = function(name) {
  28. new Animal.Mixin(this);
  29. this.name = name;
  30. return this;
  31. };
  32. __extends(Snake, Animal);
  33. Snake.prototype.move = function() {
  34. console.log("Slithering...");
  35. return Snake.__superClass__.move.call(this, 5);
  36. };
  37.  
  38. sam = new Snake("Sammy the snake");
  39.  
  40. // sam.sex => undefined
  41. // sam.getSex => 'male'
  42. // sam instanceof Animal => true
  43. // sam instanceof Snake => true
  44. // sam.thinkThenMove() => slithering...
Add Comment
Please, Sign In to add comment