Object.setConfig =  function(defaults, config){return
Object.extend(Object.clone(defaults), config || {});}

I wrote this code using a suggestion posted to the Prototype.js
support group.

Personally, I don't think it needs to be in the core prototype.js
code. I assumed it was one of those functions I would keep in my
personal prototype-addons.js. I keep hoping someone would setup a
prototype-addon.js site for all the useful code that doesn't make
sense to add to the core prototype.js library.

~ jake

On Jul 19, 1:43 pm, Jeff Watkins <[EMAIL PROTECTED]> wrote:
> This is similar to Object.extend, but you get back the original
> object and keys aren't overwritten:
> Object.applyDefaults = function(obj, defaults) {
>      obj= obj||{};
>      if (!defaults)
>          return obj;
>      for (var p in defaults) {
>          if (p in obj)
>              continue;
>          obj[p]= defaults[p];
>      }
>      return obj;
> }
> I use this all the time to accept a config hash and fill in default
> values. This allows me to define my code a bit more modularly:
> function MyClass(config) {
>         this.config= Object.applyDefaults(config, arguments.callee.DEFAULTS);}
> MyClass.DEFAULTS = {
> ...
> };
> I know the prototype way is to use Object.extend, but this allows a
> greater modularity of code. For example, I can use the same defaults
> multiple times.
> --
> Jeff Watkins
> UI Engineer, Online Apple Store

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to