How to inspect a JavaScript Bound Function

is there any way to inspect a JavaScript bound function?

I want to return a bound function from a function, and in unit testing, to assert the bound function's target, boundThis, and boundArgs. They seem to be defined as internal object in ECMAScript and cannot be accessed in program.

Is there any way to access them? or maybe some people with similar requirements have already written some module patching Function.prototype.bind()?



No, there is not (unless you fire up a debugger).

You should not test for bound functions anyway. You could achieve the exact same behaviour with a closure as well, which would not expose the closed-over variables either. And it doesn't matter. You should not test the implementation, but the behaviour - so just check whether calling the returned function does invoke the target with the expected values.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.