JavaScript private methods, asynchronous access
<p>I'm using a pattern like the one shown below to create a javascript library that has private and public methods.  The idea is that the page that includes this library would call MYLIB.login() and provide two functions for when the user clicks OK, or Cancel.</p>

<pre><code>var MYLIB = function() {
    //  private data and functions
    var showForm = function() {
        //  create and show the form
    };
    var onOK = function() {
        //  hide the form, do some internal stuff, then…
        okFunction();
    };
    var onCancel = function() {
        //  hide the form, do some internal stuff, then...
        cancelFunction();
    };

    var okFunction = null;
var cancelFunction = null;

    //  public functions 
    return {
        login : function(okf, cancelf) {
           okFunction = okf;
           calcelFunction = cancelf;
           showForm();
        },
    };  
}();
</code></pre>

<p>My question is about getting the buttons in the form to call the internal functions onOK and onCancel, which are private.  The buttons look like this:</p>

<pre><code>&lt;button onclick="onOK();"&gt;OK&lt;/button&gt;
&lt;button onclick="onCancel();"&gt;Cancel&lt;/button&gt;
</code></pre>

<p>I can get it to work if I make the functions public, but then I may as well make everything public.  How can I do what I want?  Coming from a C++/Java background, trying to be a good OO guy.  Thanks.</p>
