javascript – Is it possible to find out the context of the passed function?

Question:

For example:

 function test( func ) { // можно ли здесь узнать контекст переданной ф-ии? } function whoami() { } const ctxA = { name: "A" }; const ctxB = { name: "B" }; test( whoami.bind( ctxA)); test( whoami.bind( ctxB)); test( whoami.bind( window));

Answer:

Is it possible to find out the context of the passed function?

No.


Applied to the result of the bind function.

This function returns an unusual function , but a wrapper object. In the returned object, this function sets the [[BoundThis]] internal field – which is not available from code. And only when called, the value of this field is passed to the function and becomes available through the this .

Scroll to Top