Skip to content

Commit c551746

Browse files
committed
Make bound functions look nicely in Web Inspector "Event Listeners" pane.
1 parent ec15b2c commit c551746

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/lang/function.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,14 @@ Object.extend(Function.prototype, (function() {
108108
function bind(context) {
109109
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
110110
var __method = this, args = slice.call(arguments, 1);
111-
return function() {
111+
function bound() {
112112
var a = merge(args, arguments);
113113
return __method.apply(context, a);
114114
}
115+
bound.toString = function() {
116+
return __method.toString();
117+
};
118+
return bound;
115119
}
116120

117121
/** related to: Function#bind

test/unit/function_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ new Test.Unit.Runner({
4444
methodWithArguments.bind({ hi: 'withBindArgs' }, 'arg1', 'arg2')());
4545
this.assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4',
4646
methodWithArguments.bind({ hi: 'withBindArgsAndArgs' }, 'arg1', 'arg2')('arg3', 'arg4'));
47+
48+
this.assertEqual(func.toString(), func.bind({}).toString());
4749
},
4850

4951
testFunctionCurry: function() {

0 commit comments

Comments
 (0)