如何从绑定函数中提取此属性?

问题描述 投票:1回答:1

我想从已经绑定的函数中获取this属性的值。

function foo(){
  console.log(this.a)
}
const bar = foo.bind({a:1})
bar() // Prints 1
bar.getThis() // should return { a: 1 }

在上面的示例中,如何从变量栏提取绑定对象{ a: 1 }

javascript this
1个回答
0
投票
您无法得到,[[BoundThis]]是绑定函数对象的internal property

enter image description here

使用标准内置Function.prototype.bind方法创建的函数对象的此值的预绑定。仅使用Function.prototype.bind创建的ECMAScript对象具有[[[BoundThis]]内部属性。
© www.soinside.com 2019 - 2024. All rights reserved.