Skip to content

Commit f64f9c1

Browse files
committed
Added mixinPrototype.
1 parent 57ff6f4 commit f64f9c1

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/utils/Utils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,35 @@ Phaser.Utils = {
340340

341341
},
342342

343+
/**
344+
* Mixes in an existing mixin object with the target.
345+
* Prototype values with that have either `get` or `set` functions are created as properties via defineProperty.
346+
*
347+
* @method Phaser.Utils.mixinPrototype
348+
* @param {object} target - The target object to receive the new functions.
349+
* @param {object} mixin - The object to copy the functions from.
350+
*/
351+
mixinPrototype: function (target, mixin) {
352+
353+
var mixinKeys = Object.keys(mixin);
354+
355+
for (var i = 0; i < mixinKeys.length; i++)
356+
{
357+
var key = mixinKeys[i];
358+
var value = mixin[key];
359+
360+
if (value && (typeof value.get === 'function' || typeof value.set === 'function'))
361+
{
362+
Object.defineProperty(target, key, value);
363+
}
364+
else
365+
{
366+
target[key] = value;
367+
}
368+
}
369+
370+
},
371+
343372
/**
344373
* Mixes the source object into the destination object, returning the newly modified destination object.
345374
* Based on original code by @mudcube

0 commit comments

Comments
 (0)