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
* @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;
}
}
}
},