mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 16:48:00 +00:00
defaultArgs can do defaults on objects
This commit is contained in:
parent
6f0008b3d7
commit
b26f313bd7
1 changed files with 13 additions and 2 deletions
|
@ -203,14 +203,25 @@ define("Tone/core/Tone", [], function(){
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* if a the given is undefined, use the fallback
|
||||
* if a the given is undefined, use the fallback.
|
||||
* if both given and fallback are objects, given
|
||||
* will be augmented with whatever properties it's
|
||||
* missing which are in fallback
|
||||
*
|
||||
* @param {*} given
|
||||
* @param {*} fallback
|
||||
* @return {*}
|
||||
*/
|
||||
Tone.prototype.defaultArg = function(given, fallback){
|
||||
return isUndef(given) ? fallback : given;
|
||||
if (typeof given === "object" && typeof fallback === "object"){
|
||||
var ret = {};
|
||||
for (var prop in fallback) {
|
||||
ret[prop] = isUndef(given[prop]) ? fallback[prop] : given[prop];
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return isUndef(given) ? fallback : given;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue