Created
June 2, 2010 18:00
-
-
Save bga/422741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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; | |
| } | |
| })(); |
Author
Не знаю зачем такое надо, но я пропатчил.
Это помогает определить какой хендлер висит на событии. Когда у тебя 35000+ строк кода это бывает проблематично.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// 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))) }