我知道您可以使用
绑定函数的this值 function.bind(new_this_value, arguments)
但有没有办法访问绑定值?即是这样的:
console.log(my_function.boundValue)
换句话说,假设一个模块提供以下功能:
function getACoolFunction () {
var someFarAwayFunction = function() {console.log(this.name)}
var bound_this_value = {name: "bound this value"}
someFarAwayFunction.bind(bound_this_value)
return someFarAwayFunction;
}
我在我的代码中有这个:
import {getACoolFunction} from coolModule
var coolFunction = getACoolFunction();
// coolFunction.bound_value
如何在不更改模块的情况下从代码中获取coolFunction的绑定值?