member visibility and 'this' scope in javascript objects
<p>I still haven't quite wrapped my head around object definitions and the <code>this</code> scope in javascript. I think the (c#ish) pseudocode below sums it up quite nicely. </p>

<p>How can I define a piece of javascript code that creates an object that has all of the following properties:</p>

<ol>
<li>private members that are only visible inside the methods of the object</li>
<li>public members that are also visible outside the object</li>
<li>a (parametrized) constructor that is executed when the object is instantiated and initializes members</li>
<li>register callback inside the object that points to a method of the object itself </li>
<li>when the callback is executed inside the method (<code>PrivateMethod</code>) it is possible to access all members of the object instance, preferably using the <code>this</code> pointer</li>
</ol>

<p>.</p>

<pre><code>class MyObjectDefinition
{
    public int publicField = 0;
    private int privateField;

    public MyObjectDefinition(int parameter)
    {
        this.privateField = parameter;   
        SomethingThatWantsA.CallBack(this.PrivateMethod);
    }

    public void PublicMethod()
    {
        this.privateField--;
        this.publicField--;
    }

    private void PrivateMethod()
    {
        this.privateField++;
        this.publicField++;
    }
}

var instance = new MyObjectDefinition();    
</code></pre>
