我想从已经绑定的函数中获取this属性的值。
function foo(){
console.log(this.a)
}
const bar = foo.bind({a:1})
bar() // Prints 1
bar.getThis() // should return { a: 1 }
在上面的示例中,如何从变量栏提取绑定对象{ a: 1 }
?
[[BoundThis]]
是绑定函数对象的internal property。 使用标准内置Function.prototype.bind方法创建的函数对象的此值的预绑定。仅使用Function.prototype.bind创建的ECMAScript对象具有[[[BoundThis]]内部属性。