Can someone explain this javascript piece of code?
<p>I am trying to understand a piece of JavaScript code but for some reason i can not. Maybe the reason is that I have a different style of writing software code.</p>

<p>I am hoping some of you might have similar to the one I am trying to figure out.</p>

<p>Ok, here is the code:</p>

<pre><code>mainObj = function(obj)
{
    for (var a in obj) mainObj [a]=obj[a];

    return mainObj; //simple singleton
};

mainObj.extend_api=function(name,map,ext)
{
    var t = window[name];
    if (!t) return; //component not defined

    window[name]=function(obj)
    {
        if (obj &amp;&amp; typeof obj == "object" &amp;&amp; !obj.tagName)
            {
            var that = t.apply(this,(map._init?map._init(obj):arguments));
            //global settings
            for (var a in dhtmlx)
                if (map[a]) this[map[a]](dhtmlx[a]);            
            //local settings
            for (var a in obj){
                if (map[a]) this[map[a]](obj[a]);
                else if (a.indexOf("on")==0){
                    this.attachEvent(a,obj[a]);
            }
        }
    } 
            else
        var that = t.apply(this,arguments);

    if (map._patch) map._patch(this);
    return that||this;
    };

window[name].prototype=t.prototype;
if (ext)
    someFunction(window[name].prototype,ext);
    };
</code></pre>

<p>and finally:</p>

<pre><code>(function(){
mainObj.extend_api("ajaxSlider",{
    _init:function(obj){
        return [ obj.parent, obj.size, obj.skin, obj.vertical, obj.min, obj.max, obj.value, obj.step ];
    },
    link:"linkTo"
},{});
})();
</code></pre>
