JSFiddle - React, Tailwind, and code Playground

by JInks Peng

JavaScript

function Book(title,author) {
  var title  = title;
  var author = author;
  this.getTitle = function() {
    return 'Title: ' + title;
  }
  this.getAuthor = function() {
    return 'Author ' + author;
  }
}
function TechBook(title,author,category) {
  var category = category;
  this.getCategory = function() {
    return 'Technical Category: ' + category;
  }
  Book.apply(this,arguments);
  this.getBook = function() {
    return this.getTitle() + ' ' + author + ' ' + this.getCategory();
  }
}
window.onload = function() {
  //TechBook.prototype = new Book();
  try{
    var newBook1 = new TechBook('The Javascript Cookbook','Shelley Powers','Programming');
    var newBook2 = new TechBook('The Javascript Cookbook','Shelley Powers','Programming');
    var newBook3 = new TechBook('The Javascript Cookbook','Shelley Powers','Programming');
    Object.defineProperty(newBook1,'experience',{
      get: function() {return category},
      set: function(val) {category = val},
      enumerable: false,
      configurable: true
    });

    Object.defineProperties(newBook2,{
      'stock':{
      value: true,
      writable: true,
      enumerable: true
    },
    'age':{
      value: '13 and up',
      writable: false
    }
    });
    console.log(newBook1,newBook2,newBook3);

  } catch(e) {
    alert(e);
  }
  
}