获取函数的 this 绑定

Get function's this binding

给定一个函数,

function main() {
  // some logic
}

假设函数 mainconst obj = { name: "John Doe" } 绑定 喜欢 const fn = main.bind(obj);

现在的问题是,有没有办法获得fn函数绑定? 注意:我知道可以使用 main 函数内的 this 关键字访问绑定,但是有什么方法可以在上下文之外访问 this 值。有没有像 fn.getContext().

这样的魔术(假设的)方法

感谢您的宝贵时间。

不,没有。虽然 the new function object 有一个内部 [[BoundThis]] 插槽,但无法通过面向用户的 API.

访问该插槽