Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript object literal pattern with multiple instances
    primarykey
    data
    text
    <p>I have developed a little javscript widget to turn some nested <code>&lt;ul&gt;</code> blocks into a windows explorer style browser. I have recently learnt about the object literal pattern and decided to give it a go, so the organisation of my code is something like this:</p> <pre><code>var myExplorer = { init : function(settings) { myExplorer.config = { $wrapper : $('#explorerCategories'), $contentHolder : $j('#categoryContent'), loadingImg : '&lt;img src="../images/standard/misc/ajax_loader.gif" alt="loading" class="loading" /&gt;' } // provide for custom configuration via init() if (settings &amp;&amp; typeof(settings) == 'object') { $.extend(myExplorer.config, settings); } // some more code... }, createExpanderLink : function() { // more code }, anotherMethod : function() { // etc } } </code></pre> <p>Then in my page I set up my explorer with:</p> <pre><code>$j(function () { myExplorer.init(); } </code></pre> <p>This all works fine by the way. The problem is when I want to have more then one of these explorer style widgets on the same page. I tried passing in the different settings:</p> <pre><code>$j(function () { // first instance myExplorer.init(); //second instance var settings = { $wrapper : $('#explorerCategories2'), $contentHolder : $j('#categoryContent2') } myExplorer.init(settings); } </code></pre> <p>But this simply overwrites the config vales for the first instance which effectively breaks it. I'm beginning to realise that the object literal pattern isn't the way to go here but I'm not sure what is. Can anyone offer any pointers?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload