Skip to content

Instantly share code, notes, and snippets.

@iolo
Created December 13, 2011 02:04
Show Gist options
  • Save iolo/1470105 to your computer and use it in GitHub Desktop.
Save iolo/1470105 to your computer and use it in GitHub Desktop.
emulate ecmascript 5 function bind with javascript.
(function () {
"use strict";
if (typeof Function.prototype.bind !== 'function') {
console.log('mimic Function.prototype.bind...');
/**
* https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
*
* @param {object|null} ctx
* @param {*...} var_args
* @return {function}
*/
Function.prototype.bind = function (ctx) {
var self = this, slice = Array.prototype.slice, args = slice.call(arguments, 1);
return function () {
return self.apply(ctx, args.concat(slice.call(arguments)));
}
}
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment