Use Function.prototype.bind
to debug Function.prototype.bind
.
Debugging functions created with Function.prototype.bind
is not easy. Calling
toString
on a bound function gives only 'function () { [native code] }'
, and
the details of the binding are buried inside and unavailable.
With only a reference to a bound function, these questions can't be answered:
- What bound arguments does the function carry?
- What is the
this
object of the function? - What is the original function that was bound?
Answering these questions often requires deep knowledge of the entire system, or infinite patience stepping through the debugger.
Functions created with this debug version of Function.prototype.bind
will
carry binding metadata on the target
property, which is a hash object with the
following keys:
arguments
- An array of bound arguments, if anyfn
- The original functionthisObj
- The boundthis
object, if any
No changes to existing calls to Function.prototype.bind
are necessary, no
changes to existing functionality are made, and answering the three questions
posed above is now much easier.