title: Javascript Prototype reuse same method
body: <p>I have this JS file</p>
  
  <pre><code>function APIAccess(){
      this.LoadScreen = function(){
          var loadScreen = $('#loadScreen');
          if(loadScreen.html() == undefined){
              loadScreen = '&lt;div id="loadScreen" style="display: none;width: 100%; height: 100%; top: 0pt;left: 0pt;"&gt;' + 
                               '&lt;div id="loadScr" style="filter: alpha(opacity = 65);  z-index: 9999;border: medium none; margin: 0pt; padding: 0pt; width: 100%; height: 100%; top: 0pt;left: 0pt; background-color: rgb(0, 0, 0); opacity: 0.2; cursor: wait; position: fixed;"&gt;&lt;/div&gt;' +
                               '&lt;div id="loader"  style="z-index: 10000; position: fixed; padding: 0px; margin: 0px;width: 30%; top: 40%; left: 35%; text-align: center;cursor: wait; "&gt;' +
                               '&lt;img src="img/ajax-loader.gif" alt="loading" /&gt;&lt;/div&gt;&lt;/div&gt;';
              $(document.body).append(loadScreen);
          }
      };
  
      this.APICall = function(url, params, method, callback){
          this.LoadScreen();  
          var postData = null;
          if(params != null){
              postData = JSON.stringify(params);
          }   
          if(url.toLowerCase().indexOf("http") &lt; 0){
              url = "http://" + url;
          }   
          $('#loadScreen').show(function(){
              $.ajax({
                url: url,
                async: true,
                type: method,
                data: postData,
                success: function(data){
                  $('#loadScreen').hide();
                  callback(data);
                },
                error:function(data){
                    alert("failure");
                    return false;
                }   
              }); 
          });
      };
  }
  
  function Domain(reqCallback){
      this.url = 'http://beta.test123.net/api/domain';
      this.params = null;
      this.method = 'GET';
      this.callback = function(data){
          setCookie("domain", data);
          if(typeof reqCallback != null){
              reqCallback(data);
          }
      };
      this.request = this.APICall(this.url, this.params, this.method, this.callback);
  }
  Domain.prototype = new APIAccess;
  
  function Login(usermail, pass, reqCallback){
      var domainUrl = getCookie("domain");
      if(domainUrl == null)
          return false;
      else
          domainUrl += '/api/login';
  
      this.url = domainUrl;
      this.params = {"email": usermail, "password": password};
      this.method = 'POST';
      this.callback = function(data){
          setCookie("login", data);
          if(typeof reqCallback != null){
              reqCallback(data);
          }
      };
      this.request = this.APICall(this.url, this.params, this.method, this.callback);
  }
  Login.prototype = new APIAccess;
  </code></pre>
  
  <p>If you see the method <code>this.request = this.APICall(this.url, this.params, this.method, this.callback);</code> will be repeated everytime. I wish it could be placed in APIAccess function. can you please suggest what can be done.</p>
  
  <p>I use this in my html as this</p>
  
  <pre><code>$(document).ready(function(){
              var domain = new Domain(function(data){
                  alert(data);
              });
              domain.request;
          });
  </code></pre>