2011-08-14 21:35:36 +00:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
var slice = Array.prototype.slice,
|
2011-08-29 16:09:32 +00:00
|
|
|
apply = Function.prototype.apply,
|
|
|
|
|
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
|
|
|
|
|
* @param {Any[]} [...] Values to pass to a bound function
|
|
|
|
|
* @return {Function}
|
|
|
|
|
*/
|
2011-08-29 16:09:32 +00:00
|
|
|
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;
|
|
|
|
|
};
|
2011-08-14 21:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})();
|