mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Added 'replace' parameter to mixinPrototype.
This commit is contained in:
parent
9fd5ae119b
commit
52f4a037a3
1 changed files with 14 additions and 4 deletions
|
@ -347,8 +347,11 @@ Phaser.Utils = {
|
|||
* @method Phaser.Utils.mixinPrototype
|
||||
* @param {object} target - The target object to receive the new functions.
|
||||
* @param {object} mixin - The object to copy the functions from.
|
||||
* @param {boolean} [replace=false] - If the target object already has a matching function should it be overwritten or not?
|
||||
*/
|
||||
mixinPrototype: function (target, mixin) {
|
||||
mixinPrototype: function (target, mixin, replace) {
|
||||
|
||||
if (typeof replace === 'undefined') { replace = false; }
|
||||
|
||||
var mixinKeys = Object.keys(mixin);
|
||||
|
||||
|
@ -357,6 +360,12 @@ Phaser.Utils = {
|
|||
var key = mixinKeys[i];
|
||||
var value = mixin[key];
|
||||
|
||||
if (!replace && target[key])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value && (typeof value.get === 'function' || typeof value.set === 'function'))
|
||||
{
|
||||
Object.defineProperty(target, key, value);
|
||||
|
@ -366,6 +375,7 @@ Phaser.Utils = {
|
|||
target[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue