News for hackers. Stuff that matters.
Re:Advanced JavaScript Techniques by yannis on Friday October 09, 2009 @02:45PM (#872166)
Thanks for sharing your rule of thumb. I have observed that inevitably most objects/functions require three 'groups' of variables, more or less I use this pattern and I would appreciate your thoughts.

   - Defaults: Must be defined within the object literal
   - User Options : part of the function arguments 
                    (user can use an object literal,
                     anon function etc.) 
   - Settings : The actual mixin used by the methods

 function aProblem(arg1, arg2, options){ 
    // define the necessary defaults
    var defaults={} //define defaults
    // use a mixin algo to combine options and
    // defaults
    var settings = mixin(options, defaults); 
    // main function routines 
    var myObj={};

    return myObj={   
      property1 : settings.property1,
      property2 : settings.property2
    }
 }

There are no comments on this comment yet.