Skip to content

Instantly share code, notes, and snippets.

@bga
Created June 2, 2010 18:00
Show Gist options
  • Save bga/422741 to your computer and use it in GitHub Desktop.
Save bga/422741 to your computer and use it in GitHub Desktop.
(function()
{
var _oldBind = Function.prototype.bind, _slice = Array.prototype.slice,
_toString = function()
{
return '' + this._fn;
};
Function.prototype.bind = function(that)
{
var _ret = _oldBind.apply(this, arguments);
_ret.that = arguments[0];
_ret.args = _slice.call(arguments, 1);
_ret._fn = this;
_ret.prototype = this.prototype;
_ret.toString = _toString;
return _ret;
}
})();
@NV
Copy link

NV commented Jun 2, 2010

// from Web Inspector
Function.prototype.bind = function(thisObject)
{
    var func = this;
    var args = Array.prototype.slice.call(arguments, 1);
    return function() { return func.apply(thisObject, args.concat(Array.prototype.slice.call(arguments, 0))) };
}

// ... Your bind ...

function fuu(){return 1}

equals(
  fuu.bind({}).toString(), 
  "function fuu(){return 1}"
);
// Fail!
// Expected: function fuu(){return 1}
// Actual:   function() { return func.apply(thisObject, args.concat(Array.prototype.slice.call(arguments, 0))) }

@bga
Copy link
Author

bga commented Jun 2, 2010

Не знаю зачем такое надо, но я пропатчил.

@NV
Copy link

NV commented Jun 2, 2010

Это помогает определить какой хендлер висит на событии. Когда у тебя 35000+ строк кода это бывает проблематично.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment