phaser/src/tweens/builders/GetNewValue.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2018-02-10 17:11:36 +00:00
/**
* [description]
*
* @function Phaser.Tweens.Builders.GetNewValue
* @since 3.0.0
*
* @param {object} source - [description]
* @param {string} key - [description]
2018-03-20 16:15:49 +00:00
* @param {*} defaultValue - [description]
2018-02-10 17:11:36 +00:00
*
* @return {function} [description]
*/
var GetNewValue = function (source, key, defaultValue)
{
var valueCallback;
if (source.hasOwnProperty(key))
{
var t = typeof(source[key]);
if (t === 'function')
{
valueCallback = function (index, totalTargets, target)
{
return source[key](index, totalTargets, target);
};
}
else
{
valueCallback = function ()
{
return source[key];
};
}
}
else if (typeof defaultValue === 'function')
{
valueCallback = defaultValue;
}
else
{
valueCallback = function ()
{
return defaultValue;
};
}
return valueCallback;
};
module.exports = GetNewValue;