Define Base.initialize() as a general purpose way to initialize a newly created object with values from a provided object and default values from another, in case they are not provided.

This commit is contained in:
Jürg Lehni 2011-05-17 13:12:19 +01:00
parent 5369b251ae
commit 7d1d6fa9da

View file

@ -43,6 +43,14 @@ Base.inject({
return res;
},
initialize: function(object, values, defaults) {
if (!values)
values = defaults;
return Base.each(defaults, function(value, key) {
this[key] = values[key] || value;
}, object);
},
/**
* Utility function for adding and removing items from a list of which
* each entry keeps a reference to its index in the list in the private