Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Book(title, author, year){
- this.title = title;
- this.author = author;
- this.year = year;
- }
- const book1 = new Book('Snow', 'Jon Snow', '2017');
- Book.prototype.getSummary = function() {
- return `${this.title} was written by ${this.author} in ${this.year}`;
- }
- Book.prototype.getAge = function() {
- const years = new Date().getFullYear() - this.year;
- return `${this.title} is ${years} years old`;
- };
- Magazine.prototype = Object.create(Book.prototype);
- function Magazine(title, author, year, month){
- Book.call(this, title, author, year);
- this.month = month;
- }
- const mag1 = new Magazine('Magi', 'Joel Tim', '2018', `Jan`);
- const bookProtos = {
- getSummary: function() {
- return `${this.title} was written by ${this.author} in ${this.year}`;
- },
- getAge: function() {
- const years = new Date().getFullYear() - this.year;
- return `${this.title} is ${years} years old`;
- }
- };
- const book3 = Object.create(Book.prototype);
- book3.title = 'Book One';
- book3.author = 'OneM';
- book3.year = '2015';
- const book3 = Object.create(bookProtos, {
- title: {value: 'Book One'},
- author: {value: 'OneM'},
- year: {value: '2015'}
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement