Guest User

Untitled

a guest
Aug 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. // Constructor Pattern
  2. // -------------------
  3.  
  4. // Basic Constructor
  5. function Car(make, model, year) {
  6. this.make = make;
  7. this.model = model;
  8. this.year = year;
  9.  
  10. callIt = function() {
  11. return "demo:";
  12. }
  13.  
  14. this.callItAll = function() {
  15. return callIt()+this.make+this.model+this.year;
  16. }
  17. }
  18.  
  19. var audi = new Car(' Audi ',' A7 ',2007);
  20. var tesla = new Car(' Tesla ',' Model S ',2017);
  21.  
  22. console.log(audi);
  23. console.log(audi.callItAll());
  24. console.log(tesla);
  25. console.log(tesla.callItAll());
  26. //console.log(audi.callIt());
  27.  
  28. // With prototypes
  29. function Bike(make, model, year) {
  30. this.make = make;
  31. this.model = model;
  32. this.year = year;
  33.  
  34. callIt = function() {
  35. return "demo:";
  36. }
  37. }
  38. Bike.prototype.callItAll = function() {
  39. return callIt()+this.make+this.model+this.year;
  40. }
  41.  
  42. var harley = new Bike(' Harley ',' Iron ',2007);
  43. var ducati = new Bike(' Ducati ',' Diavel ',2017);
  44.  
  45. console.log(harley);
  46. console.log(harley.callItAll());
  47. console.log(ducati);
  48. console.log(ducati.callItAll());
Add Comment
Please, Sign In to add comment