mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 06:44:44 +00:00
34 lines
No EOL
1.1 KiB
JavaScript
34 lines
No EOL
1.1 KiB
JavaScript
(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;
|
|
};
|
|
}
|
|
|
|
})(); |