Skip to content

Commit

Permalink
Make bound functions look nicely in Web Inspector "Event Listeners" p…
Browse files Browse the repository at this point in the history
…ane.
  • Loading branch information
NV committed Jun 4, 2010
1 parent ec15b2c commit c551746
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lang/function.js
Expand Up @@ -108,10 +108,14 @@ Object.extend(Function.prototype, (function() {
function bind(context) {
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
var __method = this, args = slice.call(arguments, 1);
return function() {
function bound() {
var a = merge(args, arguments);
return __method.apply(context, a);
}
bound.toString = function() {
return __method.toString();
};
return bound;
}

/** related to: Function#bind
Expand Down
2 changes: 2 additions & 0 deletions test/unit/function_test.js
Expand Up @@ -44,6 +44,8 @@ new Test.Unit.Runner({
methodWithArguments.bind({ hi: 'withBindArgs' }, 'arg1', 'arg2')());
this.assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4',
methodWithArguments.bind({ hi: 'withBindArgsAndArgs' }, 'arg1', 'arg2')('arg3', 'arg4'));

this.assertEqual(func.toString(), func.bind({}).toString());
},

testFunctionCurry: function() {
Expand Down

1 comment on commit c551746

@NV
Copy link
Owner Author

@NV NV commented on c551746 Jun 4, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.