get set access in javascript object literals
<p>Using object literals for the first time and it seems I don't quite understand them right. What I need is private variables with the scope of the object and therefore accessible to all functions in the object literal.</p>

<p>Here's the issue:</p>

<p>I have a simple object literal for a map object</p>

<pre><code>var mapObj = {

    init: function (lat, lng, documentID) {
        var myOptions = {
            center: new google.maps.LatLng(lat, lng),
            zoom: 18,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById(documentID),
                myOptions);

        return map;
    },

    setMarker: function (lat, lng, map, contentObj) {
        var myLatlng = new google.maps.LatLng(lat, lng);
        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: "Hello World!",
            content: contentObj
        });
    }
};
</code></pre>

<p>This is all fine, and I get to use it as mapObj.init(....) and mapObj.setMarker(...) which work perfectly.</p>

<p>What I want to be able to do is store some of these variable values - like 'map' in the init() method, and then have it accessible for other methods. For e.g. I should not need to pass 'map' in the setMarker, as the mapObj should hold the map internally after the init method.</p>

<p>Similarly I'd like to be able to do mapObj.getMap() to access the map object created in init.</p>

<p>I'm unable to figure out how it works. Declaring var map as</p>

<pre><code>var mapObj {
   var map
}
</code></pre>

<p>for e.g throws errors. </p>

<p>Am I expecting this to work too much like C#? Should I be using the classic javascript 'class' constructions? Any pointers will help so I can move on.</p>

<p>Thanks</p>
