mirror of
https://github.com/photonstorm/phaser
synced 2025-01-12 05:08:54 +00:00
42 lines
1,014 B
JavaScript
42 lines
1,014 B
JavaScript
/**
|
|
* A polyfill for Function.prototype.bind
|
|
*/
|
|
if (!Function.prototype.bind) {
|
|
|
|
/* jshint freeze: false */
|
|
Function.prototype.bind = (function () {
|
|
|
|
var slice = Array.prototype.slice;
|
|
|
|
return function (thisArg) {
|
|
|
|
var target = this, boundArgs = slice.call(arguments, 1);
|
|
|
|
if (typeof target !== 'function')
|
|
{
|
|
throw new TypeError();
|
|
}
|
|
|
|
function bound() {
|
|
var args = boundArgs.concat(slice.call(arguments));
|
|
target.apply(this instanceof bound ? this : thisArg, args);
|
|
}
|
|
|
|
bound.prototype = (function F(proto) {
|
|
if (proto)
|
|
{
|
|
F.prototype = proto;
|
|
}
|
|
|
|
if (!(this instanceof F))
|
|
{
|
|
/* jshint supernew: true */
|
|
return new F;
|
|
}
|
|
})(target.prototype);
|
|
|
|
return bound;
|
|
};
|
|
})();
|
|
}
|
|
|