3 ms·
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 patte
by yannis 17y ago
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
}
}