 <p>While @Gnostus is correct about the prototype placement, you have an issue because you're making an asynchronous request, but are attempting to use the response immediately after sending the request.</p> <p>In other words, the code <em>after</em> your <code>loadMore()</code> call runs <em>before</em> the response is received.</p> <p>Change your prototype to accept a <code>function</code> to be used in the callback. </p> <pre><code> // accept a function to call upon success ---------------v MyLib.prototype.loadMore = function (id, loadingDivId, url, fn) { if (this.current &gt; -1) { this.current++; $(loadingDivId).html("&lt;h3&gt;Loading more records please wait...&lt;/h3&gt;"); $.get(url + this.current, function (data) { if (data != '') { $(id).append(data); $(loadingDivId).empty(); } else { this.current = -1; // ------------v------call the function fn(); $(loadingDivId).html("&lt;h3&gt;&lt;i&gt;-- No more results -- &lt;/i&gt;&lt;/h3&gt;"); } }); } } </code></pre> <p>Then pass in the functionality that relies on the response.</p> <pre><code>$('#loadMore').click(function () { if (lib.current &gt; -1) { // pass in your function -----------------------------v lib.loadMore("#results", "#loading", '/home/search/', function() { // This if() statement could be removed, since it will // always be "true" in the callback. // Just do the $("#loadMore").hide(); if (lib.current == -1) { $("#loadMore").hide(); } }); } return false; }); </code></pre> <p>Or if this will be standard functionality, you could add the function to the <code>prototype</code> of <code>MyLib</code>, and just have it accept the relevant arguments. Then your <code>loadMore</code> can simply call it from <code>this</code>.</p>