Given a function, is there a way to find out the object that holds it?
var dog = {
bark: function() { alert('dfd') },
name: 'Bill'
}
function getNameFromBark(barkFunc){
//How to implement this method?
}
getNameFromBack(dog.bark); //I would like this to return Bill.
Why not just
dog.name?Functions can be bound to an object. It can access the properties of that object using the
thiskeyword. You can rebind functions with thebindfunction, which changes the value ofthis.There is no way that I know of to ask a function what it is bound to.
like: