Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Book(title, author, year){
  2.     this.title = title;
  3.     this.author = author;
  4.     this.year = year;
  5.  
  6. }
  7.  
  8. const book1 = new Book('Snow', 'Jon Snow', '2017');
  9.  
  10. Book.prototype.getSummary = function() {
  11.     return `${this.title} was written  by ${this.author} in ${this.year}`;
  12. }
  13.  
  14. Book.prototype.getAge = function() {
  15.     const years = new Date().getFullYear() - this.year;
  16.     return `${this.title} is ${years} years old`;
  17. };
  18.  
  19. Magazine.prototype = Object.create(Book.prototype);
  20.  
  21. function Magazine(title, author, year, month){
  22.     Book.call(this, title, author, year);
  23.     this.month = month;
  24. }
  25.  
  26.  
  27.  
  28. const mag1 = new Magazine('Magi', 'Joel Tim', '2018', `Jan`);
  29.  
  30.  
  31.  
  32. const bookProtos = {
  33.     getSummary: function() {
  34.         return `${this.title} was written  by ${this.author} in ${this.year}`;
  35.     },
  36.     getAge: function() {
  37.         const years = new Date().getFullYear() - this.year;
  38.         return `${this.title} is ${years} years old`;
  39.     }
  40. };
  41.  
  42. const book3 = Object.create(Book.prototype);
  43. book3.title = 'Book One';
  44. book3.author = 'OneM';
  45. book3.year = '2015';
  46.  
  47. const book3 = Object.create(bookProtos, {
  48.     title: {value: 'Book One'},
  49.     author: {value: 'OneM'},
  50.     year: {value: '2015'}
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement