Added 'replace' parameter to mixinPrototype.

This commit is contained in:
photonstorm 2015-02-17 06:01:25 +00:00
parent 9fd5ae119b
commit 52f4a037a3

View file

@ -347,8 +347,11 @@ Phaser.Utils = {
* @method Phaser.Utils.mixinPrototype * @method Phaser.Utils.mixinPrototype
* @param {object} target - The target object to receive the new functions. * @param {object} target - The target object to receive the new functions.
* @param {object} mixin - The object to copy the functions from. * @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); var mixinKeys = Object.keys(mixin);
@ -357,13 +360,20 @@ Phaser.Utils = {
var key = mixinKeys[i]; var key = mixinKeys[i];
var value = mixin[key]; var value = mixin[key];
if (value && (typeof value.get === 'function' || typeof value.set === 'function')) if (!replace && target[key])
{ {
Object.defineProperty(target, key, value); continue;
} }
else else
{ {
target[key] = value; if (value && (typeof value.get === 'function' || typeof value.set === 'function'))
{
Object.defineProperty(target, key, value);
}
else
{
target[key] = value;
}
} }
} }