Accessing [[BoundThis]]
is restricted as it is considered an internal property of bound function objects.
However, you can still view it in the console:
https://i.stack.imgur.com/FHydr.png
The pre-bound this value of a function Object is created using the native built-in Function.prototype.bind method. Only ECMAScript objects created through Function.prototype.bind have a [[BoundThis]] internal property.
According to Bergi, "to utilize it within your program logic, you would need to implement your own version of bind that reveals this value as a property".
Although, if modifications can be made to the foo()
function, you could try something like this:
function foo() {
console.log(this.a);
return {
getThis: () => this
};
}
const bar = foo.bind({ a: 1 });
console.log(bar().getThis()) // { "a": 1 }