title: Calling prototype method inside function not working
body: <p><br/>
  I am trying to <em>create one gallery class</em> using <strong><em>Javascript</em></strong> and <strong><em>jQuery</em></strong>.</p>
  
  <p>I have some <em>prototype function</em> for that gallery class, but when I try to access those functions inside class it shows error.<br/></p>
  
  <pre><code>Uncaught TypeError: Gallery.start is not a function
  </code></pre>
  
  <p><strong><a href="https://jsfiddle.net/sureshpattu/8upw9u66/1/" rel="nofollow">My JSfiddle Link</a></strong> <br/><br/>
  Here is my Javascript:<br/></p>
  
  <pre><code>/**
   *
   * @param options should be object of following
   * options.images Array of gallery images URL
   * options.start slide starting point
   * options.autoPlay This option will be false by default
   *
   */
  function Gallery(options) {
    var _this = this;
    var galleryOptions = options;
  
    function randomString(len, charSet) {
      var ranString = '';
      var randomPoz;
      charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      for (var i = 0; i &lt; len; i++) {
        randomPoz = Math.floor(Math.random() * charSet.length);
        ranString = ranString + charSet.substring(randomPoz, randomPoz + 1);
      }
      return ranString;
    }
  
    function addThumbnail(imgSrc) {
      return '&lt;li class="thumbnail__list"&gt;&lt;img src="' + imgSrc + '" class="thumbnail__list-img" /&gt;&lt;/li&gt;';
    }
  
    function renderThumbnail(imgArr) {
      var html = [];
      if (imgArr) {
        $.each(imgArr, function(i, v) {
          html.push(addThumbnail(v));
        });
      }
      return '&lt;ul class="gallery__thumbnail__container"&gt;' + html.join('') + '&lt;/ul&gt;';
    }
  
    function getPlaceholder() {
      return 'dummy.jpg';
    }
  
    function disableNext(thisObj) {
      thisObj.galleryElement.find('.next').addClass('disabled');
    }
  
    function disablePrev(thisObj) {
      thisObj.galleryElement.find('.prev').addClass('disabled');
    }
  
    function enableNext(thisObj) {
      thisObj.galleryElement.find('.next').removeClass('disabled');
    }
  
    function enablePrev(thisObj) {
      thisObj.galleryElement.find('.prev').removeClass('disabled');
    }
  
    function togglePrevNext(self) {
      if (self._opt.currIndex === (self._opt.imagesLength)) {
        disableNext(self);
      } else {
        enableNext(self);
      }
      if ((self._opt.currIndex - 1) === 0) {
        disablePrev(self);
      } else {
        enablePrev(self);
      }
    }
  
    function controls() {
      var html = [];
      html.push('&lt;div class="prev sz-icon-arrow-left"&gt;&lt;/div&gt;');
      html.push('&lt;div class="next sz-icon-arrow-right"&gt;&lt;/div&gt;');
      return '&lt;div class="gallery__controls"&gt;' + html.join('') + '&lt;/div&gt;';
    }
  
    function bindClickEvents(galleryElement) {
      galleryElement.on('click', '.start', function() {
        _this.start();
      });
      galleryElement.find('.stop').on('click', function() {
        _this.stop();
      });
      galleryElement.find('.prev').on('click', function() {
        _this.prev();
      });
      galleryElement.find('.next').on('click', function() {
        _this.next();
      });
      galleryElement.find('.thumbnail__list').on('click', function() {
        _this.goTo(Number($(this).index()) + 1);
      });
    }
  
    function checkOptions(option) {
      var opt = option;
      opt.images = (opt.images.length) ? opt.images : getPlaceholder();
      opt.thumbnail = (opt.thumbnail) ? true : false;
      opt.fullScreen = (opt.fullScreen) ? true : false;
      opt.container = (opt.fullScreen) ? 'body' : opt.container;
      opt.container = (opt.container) ? opt.container : 'body';
      opt.autoPlay = (opt.autoPlay) ? true : false;
      opt.start = (opt.start &amp;&amp; opt.start &lt;= Number(opt.images.length)) ? opt.start : 1;
      return opt;
    }
  
    Gallery.init = function() {
      var html;
      _this._opt = checkOptions(galleryOptions);
      _this._opt.imagesLength = Number(_this._opt.images.length);
      _this._opt.currIndex = Number(_this._opt.start);
      _this._opt.elementName = 'gallery--' + randomString(5, 'SZgallery');
      if (_this._opt.fullScreen) {
        html = '&lt;div class="pop-up__model ' + _this._opt.elementName + '"&gt;' +
          '&lt;div class="pop-up__model-table"&gt;' +
          '&lt;div class="pop-up__model-cell"&gt;' +
          '&lt;div class="gallery"&gt;&lt;div class="pop-up__model-content"&gt;' +
          '&lt;div class="gallery__inner-wrapper"&gt;&lt;/div&gt;' +
          '&lt;/div&gt;&lt;/div&gt;' +
          '&lt;/div&gt;&lt;/div&gt;' +
          '&lt;/div&gt;';
        $(_this._opt.container).append('', html);
        if (_this._opt.thumbnail) {
          $('.pop-up__model-content').append('', '&lt;div class="thumbnail__list-wrapper"&gt;' + renderThumbnail(options.images) + '&lt;/div&gt;').append('', controls());
        }
      } else {
        $(_this._opt.container).append('', '&lt;div class="gallery gallery--hidden ' + _this._opt.elementName + '"&gt;&lt;/div&gt;');
      }
      _this.galleryElement = $('.' + _this._opt.elementName);
      if (_this._opt.fullScreen) {
        _this.galleryElement.find('.gallery__inner-wrapper').append('', '&lt;div class="gallery__img-holder"&gt;' +
          '&lt;img class="gallery__img-preview" src="' + _this._opt.images[_this._opt.start - 1] + '"/&gt;' +
          '&lt;/div&gt;');
      } else {
        _this.galleryElement.append('', '&lt;div class="gallery__img-holder"&gt;' +
          '&lt;img class="gallery__img-preview" src="' + _this._opt.images[_this._opt.start - 1] + '"/&gt;' +
          '&lt;/div&gt;');
      }
      if (_this._opt.thumbnail) {
        _this.galleryElement.append('', renderThumbnail(options.images)).append(controls());
      } else {
        _this.galleryElement.append('', controls());
      }
  
      if (_this._opt.autoPlay) {
        Gallery.start();
      }
      bindClickEvents(_this.galleryElement);
    };
  
    Gallery.prototype = {
      start: function() {
        _this.goTo(_this._opt.currIndex);
        _this.galleryElement.removeClass('gallery--hidden');
        console.log('started', _this._opt);
        if (_this._opt.fullScreen) {
          $('.pop-up__model').addClass('is_visible');
        }
      },
      stop: function() {
        _this.galleryElement.addClass('gallery--hidden');
      },
      next: function() {
        if (_this._opt.currIndex &lt;= (_this._opt.imagesLength - 1)) {
          _this._opt.currIndex++;
          _this.goTo(_this._opt.currIndex);
        }
      },
      prev: function() {
        if ((_this._opt.currIndex - 1) !== 0) {
          _this._opt.currIndex--;
          _this.goTo(_this._opt.currIndex);
        }
      },
      goTo: function(imgNo) {
        var thumbnail;
        _this._opt.currIndex = Number(imgNo);
        if (_this._opt.images[imgNo - 1]) {
          _this.galleryElement.find('.gallery__img-preview').attr('src', _this._opt.images[imgNo - 1]);
        }
        if (_this._opt.thumbnail) {
          thumbnail = _this.galleryElement.find('.thumbnail__list');
          thumbnail.removeClass('active');
          thumbnail.eq(imgNo - 1).addClass('active');
        }
        togglePrevNext(_this);
      },
      destroy: function() {
        console.log('destroyed');
      }
    };
  
    return Gallery;
  }
  
  var imgArr = ['images/placeholder-1.png', 'images/placeholder-2.png', 'images/placeholder-3.jpg', 'images/placeholder-4.jpg'];
  
  
  var hotelPhotosGallery = new Gallery({
    images: imgArr,
    autoPlay: true,
    container: '.photo-list'
  });
  hotelPhotosGallery.init();
  </code></pre>