mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Added Object.Merge and Object.MergeRight.
This commit is contained in:
parent
bd462e29bd
commit
b1b03c118d
3 changed files with 47 additions and 1 deletions
21
v3/src/utils/object/Merge.js
Normal file
21
v3/src/utils/object/Merge.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Creates a new Object using all values from obj1 and obj2.
|
||||
// If a value exists in both obj1 and obj2, the value in obj1 is used.
|
||||
|
||||
var Clone = require('./Clone');
|
||||
|
||||
var Merge = function (obj1, obj2)
|
||||
{
|
||||
var clone = Clone(obj1);
|
||||
|
||||
for (var key in obj2)
|
||||
{
|
||||
if (!clone.hasOwnProperty(key))
|
||||
{
|
||||
clone[key] = obj2[key];
|
||||
}
|
||||
}
|
||||
|
||||
return clone;
|
||||
};
|
||||
|
||||
module.exports = Merge;
|
23
v3/src/utils/object/MergeRight.js
Normal file
23
v3/src/utils/object/MergeRight.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Creates a new Object using all values from obj1.
|
||||
//
|
||||
// Then scans obj2. If a property is found in obj2 that *also* exists in obj1,
|
||||
// the value from obj2 is used, otherwise the property is skipped.
|
||||
|
||||
var Clone = require('./Clone');
|
||||
|
||||
var MergeRight = function (obj1, obj2)
|
||||
{
|
||||
var clone = Clone(obj1);
|
||||
|
||||
for (var key in obj2)
|
||||
{
|
||||
if (clone.hasOwnProperty(key))
|
||||
{
|
||||
clone[key] = obj2[key];
|
||||
}
|
||||
}
|
||||
|
||||
return clone;
|
||||
};
|
||||
|
||||
module.exports = MergeRight;
|
|
@ -7,6 +7,8 @@ module.exports = {
|
|||
GetAdvancedValue: require('./GetAdvancedValue'),
|
||||
GetMinMaxValue: require('./GetMinMaxValue'),
|
||||
GetValue: require('./GetValue'),
|
||||
IsPlainObject: require('./IsPlainObject')
|
||||
IsPlainObject: require('./IsPlainObject'),
|
||||
Merge: require('./Merge'),
|
||||
MergeRight: require('./MergeRight')
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue