fabric.js/src/util/lang_function.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

(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
* @param {Any[]} [...] Values to pass to a bound function
* @return {Function}
*/
Function.prototype.bind = function(thisArg) {
var fn = this, args = slice.call(arguments, 1), bound;
if (args.length) {
bound = function() {
return apply.call(fn, this instanceof dummy ? this : thisArg, args.concat(slice.call(arguments)));
};
}
else {
bound = function() {
return apply.call(fn, this instanceof dummy ? this : thisArg, arguments);
};
}
dummy.prototype = this.prototype;
bound.prototype = new dummy;
return bound;
};
}
})();