Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get function's this binding [duplicate]

Given a function,

function main() {
  // some logic
}

Lets assume the function main is bind with const obj = { name: "John Doe" } like const fn = main.bind(obj);

Now the question is, Is there a way to get the fn function binding? Note: i know binding can be accessed using the this keyword inside the main function but is there any way to access this value outside the context. is there any magic (hypothetical) method like fn.getContext().

Thank you for your time.

like image 912
Kharel Avatar asked Sep 03 '25 09:09

Kharel


1 Answers

No there is not. While the new function object has an internal [[BoundThis]] slot, that slot is not accessible via a user-facing API.

like image 136
Felix Kling Avatar answered Sep 04 '25 22:09

Felix Kling