rtivital
2/24/2016 - 3:26 PM

inheritance.js

var Gallery = (function() {
  var Gallery = function(images) {
    this.images = images;
  };

  return Gallery;
})();

var Photo = (function() {
  var Photo = function(settings) {
    this.width = setting.width || 0;
    this.height = settings.height || 0;
    this.src = settings.src || '';
  };

  var fn = Photo.prototype;

  Photo.prototype.log = function() {
    console.log('Width: ' + this.width, 'Height: ' + this.height, 'Image: ' + this.src);
  };

  return Photo;
})();

Gallery.prototype = Object.create(Photo.prototype);

Gallery.prototype.show = function() {
  console.log('Image was showen');
};

var gallery = new Gallery(['img', 'img2']);

gallery.log(); // Width: undefined Height: undefined Image: undefined
gallery.show(); // Image was showen