fabric.js/src/util/lang_function.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

/* _ES5_COMPAT_START_ */
(function() {
var slice = Array.prototype.slice,
apply = Function.prototype.apply,
Dummy = function() { };
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
* @return {Function}
*/
2012-11-23 12:38:13 +00:00
Function.prototype.bind = function(thisArg) {
var _this = this, args = slice.call(arguments, 1), bound;
2012-11-23 12:38:13 +00:00
if (args.length) {
bound = function() {
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() {
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-11-23 12:38:13 +00:00
return bound;
};
}
})();
/* _ES5_COMPAT_END_ */