Search code examples
javascriptecmascript-6ecmascript-5ecmascript-2016ecmascript-next

Get function's this binding


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.


Solution

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