mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
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:
parent
5369b251ae
commit
7d1d6fa9da
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue