Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. let running = {
  2. getDetails() {
  3. console.log(`Heading towards ${this.direction} at ${this.speed}`);
  4. }
  5. }
  6.  
  7. let Airplane = function(speed, direction){
  8. this.speed = speed;
  9. this.direction = direction;
  10. }
  11.  
  12. let boeing787 = new Airplane('400 mph', 'North');
  13. boeing787 = Object.assign(boeing787, running);
  14. console.log(boeing787.getDetails()); //Heading towards North at 400mph
  15.  
  16. //Mixins in ES6 Class
  17.  
  18. let runningStatus = {
  19. setRunnigStatus(speed, direction) {
  20. this.speed = speed;
  21. this.direction = direction;
  22. },
  23.  
  24. getRunnigStatus(){
  25. console.log(`Flying at ${this.speed} towards ${this.direction}`);
  26. }
  27. }
  28.  
  29. class Airplane {
  30. constructor(name) {
  31. this.name = name;
  32. }
  33. }
  34.  
  35. Object.assign(Airplane.prototype, runningStatus);
  36. let airplane = new Airplane("Boeing 787");
  37. airplane.setRunnigStatus("490 mph", "South East");
  38. airplane.getRunnigStatus(); // Flying at 490 mph towards South East
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement