Tengo una función vinculada a un objeto, ¿cómo puedo acceder al objeto en el mismo ámbito que la función?
let f = function(){}; class A{} f = f.bind(new A()); // console.log(f.bindedObject)¿Qué pasa en un método?
class B{ constructor(func){ this.func = func; } log(){ // console.log(this.func.bindedObject) } } class A{} let b = new B(function(){}.bind(new A())); b.log()Podrías sobrescribir el método de bind
(function() { let bind = Function.prototype.bind; Function.prototype.bind = function(newThis) { let bf = bind.apply(this, arguments); bf.newThis = newThis; return bf; }; })(); var f = function() {}; var nf = f.bind({'hello':1}); console.log('newThis', nf.newThis);