2013-05-14 16:34:45 +00:00
|
|
|
/* _ES5_COMPAT_START_ */
|
2011-08-14 21:35:36 +00:00
|
|
|
(function() {
|
2012-10-14 00:53:12 +00:00
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
var slice = Array.prototype.slice,
|
2011-08-29 16:09:32 +00:00
|
|
|
apply = Function.prototype.apply,
|
2012-10-14 00:53:12 +00:00
|
|
|
Dummy = function() { };
|
|
|
|
|
|
2011-08-14 21:35:36 +00:00
|
|
|
if (!Function.prototype.bind) {
|
|
|
|
|
/**
|
|
|
|
|
* Cross-browser approximation of ES5 Function.prototype.bind (not fully spec conforming)
|
|
|
|
|
* @see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind">Function#bind on MDN</a>
|
|
|
|
|
* @param {Object} thisArg Object to bind function to
|
2015-08-04 23:31:27 +00:00
|
|
|
* @param {Any[]} Values to pass to a bound function
|
2011-08-14 21:35:36 +00:00
|
|
|
* @return {Function}
|
|
|
|
|
*/
|
2012-11-23 12:38:13 +00:00
|
|
|
Function.prototype.bind = function(thisArg) {
|
2014-02-16 21:36:03 +00:00
|
|
|
var _this = this, args = slice.call(arguments, 1), bound;
|
2012-11-23 12:38:13 +00:00
|
|
|
if (args.length) {
|
|
|
|
|
bound = function() {
|
2014-02-16 21:36:03 +00:00
|
|
|
return apply.call(_this, this instanceof Dummy ? this : thisArg, args.concat(slice.call(arguments)));
|
2012-11-23 12:38:13 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/** @ignore */
|
|
|
|
|
bound = function() {
|
2014-02-16 21:36:03 +00:00
|
|
|
return apply.call(_this, this instanceof Dummy ? this : thisArg, arguments);
|
2012-11-23 12:38:13 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
Dummy.prototype = this.prototype;
|
|
|
|
|
bound.prototype = new Dummy();
|
2012-10-14 00:53:12 +00:00
|
|
|
|
2012-11-23 12:38:13 +00:00
|
|
|
return bound;
|
|
|
|
|
};
|
2011-08-14 21:35:36 +00:00
|
|
|
}
|
2012-10-14 00:53:12 +00:00
|
|
|
|
2013-05-14 16:34:45 +00:00
|
|
|
})();
|
|
|
|
|
/* _ES5_COMPAT_END_ */
|