var obj = {
say: function() {
function _say() {
console.log(this);
}
return _say.bind(obj);
}()
};
obj.say();
the code result is log out the global or window, I want to know why the bind method doesn't bind 'this' to the obj object context?
thisbinding, why are you not using an actual object-with-prototype? The code you show tries to ladle "instance logic" into "instance-of-nothing" code, which you can do, it's JavaScript, but it's also really... silly? What are you actually trying to do with this code? (or with code like this)return _say.bind(obj);line. (2) When it stops there, examine the value ofobj. (3) Think real hard. (4) Explain to your rubber ducky exactly why you are trying to assign the result of an IIFE to the propertysay.